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

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