2017-09-27 14:37:17 +00:00
|
|
|
+++
|
2017-10-19 11:48:50 +00:00
|
|
|
title = "Sections and Pages"
|
2017-09-27 14:37:17 +00:00
|
|
|
weight = 20
|
|
|
|
+++
|
|
|
|
|
|
|
|
Pages and sections are actually very similar.
|
|
|
|
|
|
|
|
## Page variables
|
2017-10-19 11:48:50 +00:00
|
|
|
Gutenberg will try to load the `templates/page.html` template, the `page.html` template of the theme if one is used
|
|
|
|
or will render the built-in template: a blank page.
|
2017-09-27 14:37:17 +00:00
|
|
|
|
|
|
|
Whichever template you decide to render, you will get a `page` variable in your template
|
|
|
|
with the following fields:
|
|
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
content: String;
|
|
|
|
title: String?;
|
|
|
|
description: String?;
|
|
|
|
date: String?;
|
|
|
|
slug: String;
|
|
|
|
path: String;
|
2017-11-01 13:53:28 +00:00
|
|
|
draft: Bool;
|
2017-10-31 15:41:31 +00:00
|
|
|
// the path, split on '/'
|
|
|
|
components: Array<String>;
|
2017-09-27 14:37:17 +00:00
|
|
|
permalink: String;
|
|
|
|
summary: String?;
|
|
|
|
tags: Array<String>;
|
|
|
|
category: String?;
|
|
|
|
extra: HashMap<String, Any>;
|
|
|
|
// Naive word count, will not work for languages without whitespace
|
|
|
|
word_count: Number;
|
|
|
|
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
|
|
|
|
reading_time: Number;
|
|
|
|
// `previous` and `next` are only filled if the content can be sorted
|
|
|
|
previous: Page?;
|
|
|
|
next: Page?;
|
|
|
|
// See the Table of contents section below for more details
|
|
|
|
toc: Array<Header>;
|
2018-04-08 20:12:39 +00:00
|
|
|
// Paths of colocated assets, relative to the content directory
|
|
|
|
assets: Array<String>;
|
|
|
|
// Paths of colocated image assets, ie. files with an extension of "jpg", "jpeg", "png", "gif", or "bmp"
|
|
|
|
assets_imgs: Array<String>;
|
2017-09-27 14:37:17 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Section variables
|
2017-11-26 10:34:18 +00:00
|
|
|
By default, Gutenberg will try to load `templates/index.html` for `content/_index.md`
|
|
|
|
and `templates/section.html` for others `_index.md` files. If there isn't
|
2017-09-27 14:37:17 +00:00
|
|
|
one, it will render the built-in template: a blank page.
|
|
|
|
|
|
|
|
Whichever template you decide to render, you will get a `section` variable in your template
|
|
|
|
with the following fields:
|
|
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
content: String;
|
|
|
|
title: String?;
|
|
|
|
description: String?;
|
|
|
|
date: String?;
|
|
|
|
slug: String;
|
|
|
|
path: String;
|
2017-10-31 15:41:31 +00:00
|
|
|
// the path, split on '/'
|
|
|
|
components: Array<String>;
|
2017-09-27 14:37:17 +00:00
|
|
|
permalink: String;
|
|
|
|
extra: HashMap<String, Any>;
|
|
|
|
// Pages directly in this section, sorted if asked
|
|
|
|
pages: Array<Pages>;
|
|
|
|
// Direct subsections to this section, sorted by subsections weight
|
|
|
|
subsections: Array<Section>;
|
2018-05-16 21:52:26 +00:00
|
|
|
// Unicode word count
|
2017-09-27 14:37:17 +00:00
|
|
|
word_count: Number;
|
|
|
|
// Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
|
|
|
|
reading_time: Number;
|
|
|
|
// See the Table of contents section below for more details
|
|
|
|
toc: Array<Header>;
|
|
|
|
```
|
|
|
|
|
|
|
|
## Table of contents
|
|
|
|
|
|
|
|
Both page and section have a `toc` field which corresponds to an array of `Header`.
|
|
|
|
A `Header` has the following fields:
|
|
|
|
|
|
|
|
```ts
|
2017-10-01 03:51:43 +00:00
|
|
|
// The hX level
|
2017-09-27 14:37:17 +00:00
|
|
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
2017-10-01 03:51:43 +00:00
|
|
|
// The generated slug id
|
2017-09-27 14:37:17 +00:00
|
|
|
id: String;
|
2017-10-01 03:51:43 +00:00
|
|
|
// The text of the header
|
2017-09-27 14:37:17 +00:00
|
|
|
title: String;
|
2017-10-01 03:51:43 +00:00
|
|
|
// A link pointing directly to the header, using the inserted anchor
|
2017-09-27 14:37:17 +00:00
|
|
|
permalink: String;
|
2017-10-01 03:51:43 +00:00
|
|
|
// All lower level headers below this header
|
2017-09-27 14:37:17 +00:00
|
|
|
children: Array<Header>;
|
|
|
|
```
|