惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
美团技术团队
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
F
Fortinet All Blogs
A
About on SuperTechFans
Recent Announcements
Recent Announcements
D
Docker
Vercel News
Vercel News
Engineering at Meta
Engineering at Meta
腾讯CDC
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志

博客园 - QDuck

Handlebars.js入门教程 GHOST CMS - Handlebars Themes - Further Reading GHOST CMS - Properties GHOST CMS - Redirects GHOST CMS - Channels GHOST CMS - Content Collections GHOST CMS - Content Taxonomies GHOST CMS - Custom Routes GHOST CMS - Google AMP谷歌地图 GHOST CMS - URLs & Dynamic Routing GHOST CMS - Responsive Images 图片显示 GHOST CMS - Editor编辑器 GHOST CMS - Utility Helpers公用事业帮手 GHOST CMS - Data Helpers GHOST CMS - Functional Helpers功能助手 GHOST CMS - 标签Tag GHOST CMS - Page 页面 GHOST CMS - Post 文章 GHOST CMS - 索引Index
GHOST CMS - Author作者
QDuck · 2019-12-22 · via 博客园 - QDuck

Author

Functional helpers are used to work with data objects

Use: {{#is "author"}}{{/is}} to detect this context

Description

Authors in Ghost each get their own page which lists out the posts that user wrote. You are in the author context when viewing the page thats lists all posts written by that user, as well as subsequent pages of posts. The author context is not set on posts or pages written by those authors, only on the list of posts for that author.

Routes

The default URL for author pages is /author/:slug/. The author context is also set on subsequent pages of the post list, which live at /author/:slug/page/:num/. The slugpart of the URL is based on the name of the author and can be configured in the user admin, no other part of the URL can be configured at present.

Templates

The default template for an author page is index.hbs.

You can optionally include an author.hbs file in your theme which will be used for author pages instead.

Additionally, you can provide a custom template for a specific author. If there is a author-:slug.hbs file with the :slug matching the user's slug this will be used instead.

For example, if you have an author 'John' with the url /author/john/, adding a template called author-john.hbs will cause that template to be used for John's list of posts instead of author.hbs, or index.hbs.

These templates exist in a hierarchy. Ghost looks for a template which matches the slug (author-:slug.hbs) first, then looks for author.hbs and finally uses index.hbs if neither is available.

Data

When in the author context, a template gets access to 3 objects: the author object which matches the route, an array of post objects and a pagination object. As with all contexts, all of the @blog global data is also available.

When outputting the author attributes, you can use a block expression ({{#author}}{{/author}}) to drop into the author scope and access all of the attributes. See a full list of attributes below:

Author object attributes

  • id - the incremental ID of the author
  • name - the name of the author
  • bio - the bio of the author
  • location - the author's location
  • website - the author's website
  • twitter - the author's twitter username
  • facebook - the author's facebook username
  • profile_image - the profile image associated with the author
  • cover_image - the author's cover image
  • url - the web address for the tag's page

Post list

Each of the posts can be looped through using {{#foreach 'posts'}}{{/foreach}}. The template code inside the block will be rendered for each post, and have access to all of the post object attributes.

The pagination object provided is the same everywhere. The best way to output pagination is to use the pagination helper.

Helpers

The {{#author}}{{/author}} block expression is useful for accessing all of the author attributes. Once inside the author you can access the attributes and use helpers like {{img_url}} and {{url}} to output the author's details.

Using {{#foreach 'posts'}}{{/foreach}} is the best way to loop through your posts and output each one.

If your theme does have a tag.hbs and author.hbs file all outputting similar post lists to index.hbs you may wish to use a partial to define your post list item, e.g. {{> "loop"}}. There's an example showing this in detail below.

The {{pagination}} helper is the best way to output pagination. This is fully customisable, see the pagination helper docs for details.

Example Code

author.hbs

<!-- Everything inside the #author tags pulls data from the author -->
{{#author}}
  <header>
  	{{#if profile_image}}
    	<img src="{{profile_image}})" alt="{{name}}'s Picture" />
    {{/if}}
  </header>

  <section class="author-profile">
  	<h1 class="author-title">{{name}}</h1>
    {{#if bio}}<h2 class="author-bio">{{bio}}</h2>{{/if}}

    <div class="author-meta">
      {{plural ../pagination.total empty='No posts' singular='% post' plural='% posts'}}
     </div>
  </section>
{{/author}}

<main role="main">