GHOST CMS - URLs & Dynamic Routing

URLs & Dynamic Routing

Routing is the system which maps URL patterns to data and templates within Ghost. It comes pre-configured by default, but it can also be customised extensively to build powerful custom site structures.

All of Ghost‘s routing configuration is defined in content/settings/routes.yaml - which you can edit directly, but you can also upload/download this file from within your Ghost admin panel under Settings » Labs.

If you edit the file manually, you‘ll need to restart Ghost to see the changes, but if you upload the file in admin then your routes will automatically be updated right away.

Base configuration

The default routes.yaml which comes with all new installs of Ghost sets things up with a traditional publication structure. The homepage of the site is a reverse-chronological list of the site‘s posts, with each post living on its own URL defined by a {slug}parameter, such as my-great-post. There are also additional archives of posts sorted by tag and author.

routes.yaml

routes:

collections:
  /:
    permalink: /{slug}/
    template: index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

For most publications and use-cases, this structure is exactly what‘s needed and it‘s not necessary to make any edits in order to use Ghost or develop a theme for it.

What‘s YAML?

YAML stands for Yet Another Markup Language - because there aren‘t enough unfunny acronyms in computer science. You can think of it loosely like JSON without all the brackets and commas. In short, it‘s a document format used to store nested key:valuepairs, commonly used for simple/readable configuration.

The most important thing to know when working with YAML is that it uses indentation to denote structure. That means the only type of nesting which works is 2 spaces.

The most common reason for YAML files not working is when you accidentally use the wrong type or quantity of spacing for indentation. So keep a close eye on that!

When to use dynamic routing

Maybe you want your homepage to be a simple landing page, while all of your posts appear on site.com/writing/. Maybe you actually want to split your site into two main collections of content, like /blog/ and /podcast/. Maybe you just want to change the URL of your archives from /tag/news/ to /archive/news/.

If you‘re looking to create an alternative site structure to the one described above, then dynamic routing is what you need in order to achieve all your hopes and dreams.

Okay maybe not all your hopes and dreams but at least your URLs. We‘ll start there.

Hopes and dreams come later.

原文地址:https://www.cnblogs.com/QDuck/p/12081539.html

时间: 2024-11-09 06:05:24

GHOST CMS - URLs & Dynamic Routing的相关文章

GHOST CMS - Redirects

Redirects In addition to creating routes, you can also create redirects for any time there are any changes in your URLs and you need to forward visitors Accessing the redirects file The redirects.json file is located in content/data/redirects.json an

GHOST CMS - 索引Index

Index Use: {{#is "index"}}{{/is}} to detect this context. 使用:{{#is "index"}}{{/is}}来检测这个上下文. Description描述 index is the name for the main post list in your Ghost site, the index context includes the home page and subsequent pages of th

GHOST CMS - Handlebars Themes - Further Reading

Further Reading Where you go from here is up to you, the world is your router1 Ghost's dynamic routing system is an extremely powerful way to build advanced structures for your site, and it's hard to document every possible example of what can be don

TCP/IP illustrated 第九、十章 IP Routing & Dynamic Routing Protocols

IP routing Summary 定义: IP routing 指的是 IP 如何 make routing decisions,即将 IP datagram 发到哪里去.基础:IP routing 的基础是 IP routing table, 每次发送 IP datagram 的时候,都会参照 routing table,选择合适的 route, 然后发送.IP routing table 可以创建和修改,其方法如下: 通过 ICMP redirect message 改动 通过 user

GHOST CMS -上下文概述 Context Overview

Context Overview上下文概述 Each page in a Ghost theme belongs to a context, which determines which template is used, what data will be available and what content is output by the {{body_class}} helper. Ghost主题中的每个页面都属于一个上下文,它决定使用哪个模板.哪些数据可用以及{{body_class}

GHOST CMS - Data Helpers

Data Helpers Data helpers are used to output data from your site. Use this reference list to discover what each handlebars helper can do when building a custom Ghost theme. Available data helpers @config @site navigation post url title img_url excerp

GHOST CMS - Utility Helpers公用事业帮手

Utility Helpers Utility helpers are used to perform minor, optional tasks. Use this reference list to discover what each handlebars helper can do when building a custom Ghost theme. Available utility helpers asset ghost_head/foot body_class post_clas

GHOST CMS - Custom Routes

Custom Routes Template routes allow you to map individual URLs to specific template files within a Ghost theme. For example: make /custom/ load custom.hbs Using template routes is very minimal. There's no default data associated with them, so there i

GHOST CMS - 配置 Config

Config For self-hosted Ghost users, a custom configuration file can be used to override Ghost's default behaviour. This provides you with a range of options to configure your publication to suit your needs. 对于自承载的Ghost用户,可以使用自定义配置文件覆盖Ghost的默认行为.这为您提供