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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. tags: Array<String>;
  24. category: String?;
  25. extra: HashMap<String, Any>;
  26. // Naive word count, will not work for languages without whitespace
  27. word_count: Number;
  28. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  29. reading_time: Number;
  30. // `previous` and `next` are only filled if the content can be sorted
  31. previous: Page?;
  32. next: Page?;
  33. // See the Table of contents section below for more details
  34. toc: Array<Header>;
  35. // Paths of colocated assets, relative to the content directory
  36. assets: Array<String>;
  37. // Paths of colocated image assets, ie. files with an extension of "jpg", "jpeg", "png", "gif", or "bmp"
  38. images: Array<String>;
  39. ```
  40. ## Section variables
  41. By default, Gutenberg will try to load `templates/index.html` for `content/_index.md`
  42. and `templates/section.html` for others `_index.md` files. If there isn't
  43. one, it will render the built-in template: a blank page.
  44. Whichever template you decide to render, you will get a `section` variable in your template
  45. with the following fields:
  46. ```ts
  47. content: String;
  48. title: String?;
  49. description: String?;
  50. date: String?;
  51. slug: String;
  52. path: String;
  53. // the path, split on '/'
  54. components: Array<String>;
  55. permalink: String;
  56. extra: HashMap<String, Any>;
  57. // Pages directly in this section, sorted if asked
  58. pages: Array<Pages>;
  59. // Direct subsections to this section, sorted by subsections weight
  60. subsections: Array<Section>;
  61. // Unicode word count
  62. word_count: Number;
  63. // Based on https://help.medium.com/hc/en-us/articles/214991667-Read-time
  64. reading_time: Number;
  65. // See the Table of contents section below for more details
  66. toc: Array<Header>;
  67. ```
  68. ## Table of contents
  69. Both page and section have a `toc` field which corresponds to an array of `Header`.
  70. A `Header` has the following fields:
  71. ```ts
  72. // The hX level
  73. level: 1 | 2 | 3 | 4 | 5 | 6;
  74. // The generated slug id
  75. id: String;
  76. // The text of the header
  77. title: String;
  78. // A link pointing directly to the header, using the inserted anchor
  79. permalink: String;
  80. // All lower level headers below this header
  81. children: Array<Header>;
  82. ```