You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pages-sections.md 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. +++
  2. title = "Sections and Pages"
  3. weight = 20
  4. +++
  5. Pages and sections are actually very similar.
  6. ## Page variables
  7. Gutenberg will try to load the `templates/page.html` template, the `page.html` template of the theme if one is used
  8. or will render the built-in template: a blank page.
  9. Whichever template you decide to render, you will get a `page` variable in your template
  10. with the following fields:
  11. ```ts
  12. content: String;
  13. title: String?;
  14. description: String?;
  15. date: String?;
  16. slug: String;
  17. path: String;
  18. draft: Bool;
  19. // the path, split on '/'
  20. components: Array<String>;
  21. permalink: String;
  22. summary: String?;
  23. taxonomies: HashMap<String, Array<String>>;
  24. extra: HashMap<String, Any>;
  25. // Naive word count, will not work for languages without whitespace
  26. word_count: Number;
  27. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  28. reading_time: Number;
  29. // `earlier` and `later` are only populated if the section variable `sort_by` is set to `date`
  30. earlier: Page?;
  31. later: Page?;
  32. // `heavier` and `lighter` are only populated if the section variable `sort_by` is set to `weight`
  33. heavier: Page?;
  34. lighter: Page?;
  35. // See the Table of contents section below for more details
  36. toc: Array<Header>;
  37. // Year/month/day is only set if the page has a date and month/day are 1-indexed
  38. year: Number?;
  39. month: Number?;
  40. day: Number?;
  41. // Paths of colocated assets, relative to the content directory
  42. assets: Array<String>;
  43. ```
  44. ## Section variables
  45. By default, Gutenberg will try to load `templates/index.html` for `content/_index.md`
  46. and `templates/section.html` for others `_index.md` files. If there isn't
  47. one, it will render the built-in template: a blank page.
  48. Whichever template you decide to render, you will get a `section` variable in your template
  49. with the following fields:
  50. ```ts
  51. content: String;
  52. title: String?;
  53. description: String?;
  54. date: String?;
  55. slug: String;
  56. path: String;
  57. // the path, split on '/'
  58. components: Array<String>;
  59. permalink: String;
  60. extra: HashMap<String, Any>;
  61. // Pages directly in this section, sorted if asked
  62. pages: Array<Pages>;
  63. // Direct subsections to this section, sorted by subsections weight
  64. subsections: Array<Section>;
  65. // Unicode word count
  66. word_count: Number;
  67. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  68. reading_time: Number;
  69. // See the Table of contents section below for more details
  70. toc: Array<Header>;
  71. ```
  72. ## Table of contents
  73. Both page and section have a `toc` field which corresponds to an array of `Header`.
  74. A `Header` has the following fields:
  75. ```ts
  76. // The hX level
  77. level: 1 | 2 | 3 | 4 | 5 | 6;
  78. // The generated slug id
  79. id: String;
  80. // The text of the header
  81. title: String;
  82. // A link pointing directly to the header, using the inserted anchor
  83. permalink: String;
  84. // All lower level headers below this header
  85. children: Array<Header>;
  86. ```