Guest User

Untitled

a guest
Nov 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Give this site structure:
  2.  
  3. ```
  4. │ config.toml
  5. ├───content
  6. │ └───blog
  7. │ │ post1.md
  8. │ │ post2.md
  9. │ └───post3
  10. │ index.md
  11. │ post3a.md
  12. │ post3b.md
  13. ├───layouts
  14. │ │ index.html
  15. │ ├───shortcodes
  16. │ │ page-resource.html
  17. │ └───_default
  18. │ single.html
  19. ```
  20.  
  21. `layouts/_default/single.html`:
  22.  
  23. ```
  24. <html>
  25. <body>
  26. <h1>{{ .Title }}</h1>
  27. {{ .Content }}
  28. </body>
  29. </html>
  30. ```
  31.  
  32. `layouts/index.html`:
  33.  
  34. ```
  35. <html>
  36. <body>
  37. {{- range .Pages }}
  38. <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  39. <br>
  40. {{- end }}
  41. </body>
  42. </html>
  43. ```
  44.  
  45. From `post3/index.md`, you can then reference its page resources (`page3a.md` and `page3b.md`) with a shortcode, which lives at `layouts/shortcodes/page-resource.html`:
  46.  
  47. ```
  48. {{ $page := .Page.Resources.GetMatch (.Get 0) }}
  49. {{ $page.Content }}
  50. ```
  51.  
  52. Then in your `post3/index.md`, use the shortcode:
  53.  
  54. ```
  55. ---
  56. title: "Post3"
  57. ---
  58.  
  59. Post3 content.
  60.  
  61. {{< page-resource "post3a.md" >}}
  62.  
  63. {{< page-resource "post3b.md" >}}
  64. ```
  65.  
  66. Which, for `/index.html`, will output:
  67.  
  68. ```
  69. <html>
  70. <body>
  71. <a href="/blog/post1/">Post1</a>
  72. <br>
  73. <a href="/blog/post2/">Post2</a>
  74. <br>
  75. <a href="/blog/post3/">Post3</a>
  76. <br>
  77. </body>
  78. </html>
  79. ```
  80.  
  81. And for `/blog/post3/index.html`, will output:
  82.  
  83. ```
  84. <html>
  85. <body>
  86. <h1>Post3</h1>
  87. <p>Post3 content.</p>
  88. <p>Post3a content.</p>
  89. <p>Post3b content.</p>
  90. </body>
  91. </html>
  92. ```
Add Comment
Please, Sign In to add comment