jekyll-collection-pages 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.devcontainer/devcontainer.json +27 -0
  3. data/.devcontainer/post-create.sh +17 -0
  4. data/.github/build.sh +4 -0
  5. data/.github/bump.sh +28 -0
  6. data/.github/dependabot.yml +12 -0
  7. data/.github/pr-labeler.yml +7 -0
  8. data/.github/release-drafter.yml +40 -0
  9. data/.github/release.sh +69 -0
  10. data/.github/test.sh +4 -0
  11. data/.github/workflows/ci.yml +92 -0
  12. data/.github/workflows/pr_labeler.yml +16 -0
  13. data/.github/workflows/release.yml +23 -0
  14. data/.github/workflows/release_draft.yml +61 -0
  15. data/.github/workflows/site.yml +91 -0
  16. data/.gitignore +21 -0
  17. data/.rubocop.yml +43 -0
  18. data/.rubocop_todo.yml +33 -0
  19. data/.ruby-version +1 -0
  20. data/.vscode/settings.json +5 -0
  21. data/.vscode/tasks.json +58 -0
  22. data/CODE_OF_CONDUCT.md +128 -0
  23. data/CONTRIBUTING.md +41 -0
  24. data/Gemfile +39 -0
  25. data/LICENSE +21 -0
  26. data/README.md +152 -0
  27. data/Rakefile +8 -0
  28. data/VERSION +1 -0
  29. data/demo/CODE_OF_CONDUCT.md +1 -0
  30. data/demo/_articles/jekyll-collection-pages-comparison.md +90 -0
  31. data/demo/_articles/jekyll-collection-pages-indices.md +173 -0
  32. data/demo/_articles/jekyll-for-documentation.md +399 -0
  33. data/demo/_articles/linking-obsidian-and-jekyll.md +89 -0
  34. data/demo/_config.yml +83 -0
  35. data/demo/_docs/configuration-guide.md +113 -0
  36. data/demo/_docs/examples.md +159 -0
  37. data/demo/_docs/generated-data.md +76 -0
  38. data/demo/_docs/layout-recipes.md +122 -0
  39. data/demo/_docs/quick-start.md +1 -0
  40. data/demo/_docs/troubleshooting.md +68 -0
  41. data/demo/_layouts/collection_layout.html +27 -0
  42. data/demo/_layouts/tags.html +31 -0
  43. data/demo/articles.md +18 -0
  44. data/demo/assets/img/articles.png +0 -0
  45. data/demo/assets/img/docs.png +0 -0
  46. data/demo/assets/img/jekyll-collection-pages-preview.png +0 -0
  47. data/demo/assets/img/jekyll-collection-pages.png +0 -0
  48. data/demo/assets/img/post-img-1.png +0 -0
  49. data/demo/assets/img/post-img-2.png +0 -0
  50. data/demo/assets/img/post-img-3.png +0 -0
  51. data/demo/assets/img/post-img-4.png +0 -0
  52. data/demo/contributing.md +1 -0
  53. data/demo/directory.md +36 -0
  54. data/demo/docs.md +24 -0
  55. data/demo/gallery.md +14 -0
  56. data/demo/index.md +63 -0
  57. data/demo/tags.md +15 -0
  58. data/jekyll-collection-pages.gemspec +28 -0
  59. data/lib/jekyll/collection_pages.rb +383 -0
  60. data/lib/jekyll-collection-pages.rb +4 -0
  61. metadata +126 -0
@@ -0,0 +1,399 @@
1
+ ---
2
+ title: "Using Jekyll for documentation"
3
+ date: 2024-08-02
4
+ author: Allison Thackston
5
+ image: /assets/img/post-img-2.png
6
+ tags: [jekyll, documentation, collections]
7
+ ---
8
+
9
+ In the realm of technical documentation, content is king—but structure is the kingdom. A well-organized documentation site can make the difference between a frustrating user experience and an enlightening one. When users can easily find what they're looking for, whether through intuitive navigation or efficient search, they're more likely to engage with and benefit from your documentation.
10
+
11
+ Jekyll, with its flexibility and power, has long been a favorite tool for creating documentation sites. But when it comes to organizing complex documentation structures, especially those with multiple sections, nested categories, and interrelated content, even Jekyll can use a boost. This is where the `jekyll-collection-pages` plugin shines, offering enhanced capabilities for structuring and organizing your content.
12
+
13
+ ## Structuring Your Documentation Site
14
+
15
+ The foundation of a great documentation site is its structure. A well-planned structure makes navigation intuitive and helps users quickly find the information they need.
16
+
17
+ ### Planning Your Content Hierarchy
18
+
19
+ Before diving into Jekyll configurations, take some time to plan your content hierarchy. Consider the following:
20
+
21
+ 1. What are the main sections of your documentation?
22
+ 2. Are there logical subsections within these main sections?
23
+ 3. How might users expect to navigate through your content?
24
+
25
+ For example, a software documentation site might have a structure like this:
26
+
27
+ ```
28
+ - Getting Started
29
+ - Installation
30
+ - Quick Start Guide
31
+ - User Guide
32
+ - Basic Features
33
+ - Advanced Features
34
+ - API Reference
35
+ - Troubleshooting
36
+ - FAQs
37
+ ```
38
+
39
+ ### Setting Up Collections
40
+
41
+ With your content hierarchy in mind, it's time to set up Jekyll collections. Collections in Jekyll allow you to group related content, which is perfect for documentation sites.
42
+
43
+ In your `_config.yml` file, define your collections:
44
+
45
+ ```yaml
46
+ collections:
47
+ getting_started:
48
+ output: true
49
+ permalink: /docs/getting-started/:path/
50
+ user_guide:
51
+ output: true
52
+ permalink: /docs/user-guide/:path/
53
+ api_reference:
54
+ output: true
55
+ permalink: /docs/api/:path/
56
+ troubleshooting:
57
+ output: true
58
+ permalink: /docs/troubleshooting/:path/
59
+ ```
60
+
61
+ ### Utilizing Jekyll Collection Pages
62
+
63
+ Now, let's configure the Jekyll Collection Pages plugin to work with our structure. Add this to your `_config.yml`:
64
+
65
+ ```yaml
66
+ collection_pages:
67
+ - collection: getting_started
68
+ field: category
69
+ path: docs/getting-started/categories
70
+ layout: category_page.html
71
+ - collection: user_guide
72
+ field: category
73
+ path: docs/user-guide/categories
74
+ layout: category_page.html
75
+ - collection: api_reference
76
+ field: category
77
+ path: docs/api/categories
78
+ layout: category_page.html
79
+ - collection: troubleshooting
80
+ field: category
81
+ path: docs/troubleshooting/categories
82
+ layout: category_page.html
83
+ ```
84
+
85
+ This configuration tells the plugin to create category pages for each of our documentation sections.
86
+
87
+ ### Example Structure
88
+
89
+ Let's look at how to implement this structure. Create directories for each collection in your Jekyll project:
90
+
91
+ ```
92
+ _getting_started/
93
+ _user_guide/
94
+ _api_reference/
95
+ _troubleshooting/
96
+ ```
97
+
98
+ Then, create Markdown files in these directories. For example, in `_getting_started/`:
99
+
100
+ ```markdown
101
+ ---
102
+ title: Installation
103
+ category: Setup
104
+ ---
105
+
106
+ # Installation Guide
107
+
108
+ Here's how to install the software...
109
+ ```
110
+
111
+ The `jekyll-collection-pages` plugin will automatically create a category page at `/docs/getting-started/categories/setup/index.html` listing all documents in the "Setup" category.
112
+
113
+ ## Implementing Effective Search
114
+
115
+ Even with the best structure, users often rely on search to find specific information quickly. Let's implement a search function using Lunr.js, a lightweight, full-text search library for client-side applications.
116
+
117
+ ### Setting Up Lunr.js
118
+
119
+ First, add Lunr.js to your project. You can do this by adding the following to your default layout's `<head>` section:
120
+
121
+ ```html
122
+ <script src="https://unpkg.com/lunr/lunr.js"></script>
123
+ ```
124
+
125
+ Next, create a JSON file that Lunr.js will use as its search index. Add this to your `_config.yml`:
126
+
127
+ ```yaml
128
+ plugins:
129
+ - jekyll-collection-pages
130
+ - jekyll-lunr-js-search
131
+ ```
132
+
133
+ Create a `search.json` file in your root directory:
134
+
135
+ ```liquid
136
+ {% raw %}
137
+ ---
138
+ layout: null
139
+ ---
140
+ [
141
+ {% for collection in site.collections %}
142
+ {% for doc in collection.docs %}
143
+ {
144
+ "title": {{ doc.title | jsonify }},
145
+ "content": {{ doc.content | strip_html | jsonify }},
146
+ "url": {{ doc.url | jsonify }}
147
+ }{% unless forloop.last %},{% endunless %}
148
+ {% endfor %}
149
+ {% endfor %}
150
+ ]
151
+ {% endraw %}
152
+ ```
153
+
154
+ ### Implementing the Search Interface
155
+
156
+ Create a search page (`search.html` in your root directory):
157
+
158
+ ```html
159
+ {% raw %}
160
+ ---
161
+ layout: default
162
+ title: Search
163
+ ---
164
+
165
+ <h1>Search</h1>
166
+
167
+ <input type="text" id="search-input" placeholder="Search...">
168
+
169
+ <ul id="search-results"></ul>
170
+
171
+ <script>
172
+ window.store = {
173
+ {% for collection in site.collections %}
174
+ {% for doc in collection.docs %}
175
+ "{{ doc.url | slugify }}": {
176
+ "title": "{{ doc.title | xml_escape }}",
177
+ "content": {{ doc.content | strip_html | strip_newlines | jsonify }},
178
+ "url": "{{ doc.url | xml_escape }}"
179
+ }
180
+ {% unless forloop.last %},{% endunless %}
181
+ {% endfor %}
182
+ {% endfor %}
183
+ };
184
+ </script>
185
+ <script src="/path/to/lunr.min.js"></script>
186
+ <script src="/path/to/search.js"></script>
187
+ ```
188
+
189
+ Create `search.js` in your JavaScript directory:
190
+
191
+ ```javascript
192
+ (function() {
193
+ function displaySearchResults(results, store) {
194
+ var searchResults = document.getElementById('search-results');
195
+
196
+ if (results.length) {
197
+ var appendString = '';
198
+
199
+ for (var i = 0; i < results.length; i++) {
200
+ var item = store[results[i].ref];
201
+ appendString += '<li><a href="' + item.url + '"><h3>' + item.title + '</h3></a>';
202
+ appendString += '<p>' + item.content.substring(0, 150) + '...</p></li>';
203
+ }
204
+
205
+ searchResults.innerHTML = appendString;
206
+ } else {
207
+ searchResults.innerHTML = '<li>No results found</li>';
208
+ }
209
+ }
210
+
211
+ function getQueryVariable(variable) {
212
+ var query = window.location.search.substring(1);
213
+ var vars = query.split('&');
214
+
215
+ for (var i = 0; i < vars.length; i++) {
216
+ var pair = vars[i].split('=');
217
+
218
+ if (pair[0] === variable) {
219
+ return decodeURIComponent(pair[1].replace(/\+/g, '%20'));
220
+ }
221
+ }
222
+ }
223
+
224
+ var searchTerm = getQueryVariable('query');
225
+
226
+ if (searchTerm) {
227
+ document.getElementById('search-box').setAttribute("value", searchTerm);
228
+
229
+ var idx = lunr(function () {
230
+ this.field('id');
231
+ this.field('title', { boost: 10 });
232
+ this.field('content');
233
+ });
234
+
235
+ for (var key in window.store) {
236
+ idx.add({
237
+ 'id': key,
238
+ 'title': window.store[key].title,
239
+ 'content': window.store[key].content
240
+ });
241
+ }
242
+
243
+ var results = idx.search(searchTerm);
244
+ displaySearchResults(results, window.store);
245
+ }
246
+ })();
247
+ {% endraw %}
248
+ ```
249
+
250
+ ## Leveraging jekyll-collection-pages for an Organization
251
+
252
+ The Jekyll Collection Pages plugin really shines when it comes to organizing your content. Let's explore some advanced uses.
253
+
254
+ ### Automatic Category and Tag Pages
255
+
256
+ We've already set up basic category pages. Let's customize their layout. Create `_layouts/category_page.html`:
257
+
258
+ ```html
259
+ {% raw %}
260
+ ---
261
+ layout: default
262
+ ---
263
+ <h1>{{ page.tag }}</h1>
264
+
265
+ <ul>
266
+ {% for post in page.posts %}
267
+ <li><a href="{{ post.url | relative_url }}">{{ post.title }}</a></li>
268
+ {% endfor %}
269
+ </ul>
270
+ {% endraw %}
271
+ ```
272
+
273
+ ### Creating a Dynamic Sidebar
274
+
275
+ Use collection data to generate a dynamic sidebar. Add this to your default layout:
276
+
277
+ ```html
278
+ {% raw %}
279
+ <nav class="sidebar">
280
+ {% for collection in site.collections %}
281
+ {% if collection.label != "posts" %}
282
+ <h3>{{ collection.label | capitalize | replace: "_", " " }}</h3>
283
+ <ul>
284
+ {% for doc in collection.docs %}
285
+ <li><a href="{{ doc.url | relative_url }}">{{ doc.title }}</a></li>
286
+ {% endfor %}
287
+ </ul>
288
+ {% endif %}
289
+ {% endfor %}
290
+ {% endraw %}
291
+ </nav>
292
+ ```
293
+
294
+ ### Implementing Breadcrumbs
295
+
296
+ Add breadcrumbs to your document layout for easy navigation:
297
+
298
+ ```html
299
+ {% raw %}
300
+ <div class="breadcrumbs">
301
+ <a href="{{ '/' | relative_url }}">Home</a> &raquo;
302
+ {% assign crumbs = page.url | split: '/' %}
303
+ {% for crumb in crumbs offset: 1 %}
304
+ {% if forloop.last %}
305
+ {{ page.title }}
306
+ {% else %}
307
+ <a href="{{ site.baseurl }}{% assign crumb_limit = forloop.index | plus: 1 %}{% for crumb in crumbs limit: crumb_limit %}{{ crumb | append: '/' }}{% endfor %}">{{ crumb | replace: '-', ' ' | capitalize }}</a> &raquo;
308
+ {% endif %}
309
+ {% endfor %}
310
+ {% endraw %}
311
+ </div>
312
+ ```
313
+
314
+ ### Cross-linking and Related Content
315
+
316
+ Utilize tags for suggesting related documents. In your document layout:
317
+
318
+ ```html
319
+ {% raw %}
320
+ {% if page.tags %}
321
+ <h3>Related Documents</h3>
322
+ <ul>
323
+ {% assign maxRelated = 4 %}
324
+ {% assign minCommonTags = 1 %}
325
+ {% assign maxRelatedCounter = 0 %}
326
+
327
+ {% for doc in site.documents %}
328
+ {% assign sameTagCount = 0 %}
329
+ {% for tag in doc.tags %}
330
+ {% if page.tags contains tag %}
331
+ {% assign sameTagCount = sameTagCount | plus: 1 %}
332
+ {% endif %}
333
+ {% endfor %}
334
+ {% if sameTagCount >= minCommonTags %}
335
+ <li><a href="{{ doc.url | relative_url }}">{{ doc.title }}</a></li>
336
+ {% assign maxRelatedCounter = maxRelatedCounter | plus: 1 %}
337
+ {% if maxRelatedCounter >= maxRelated %}
338
+ {% break %}
339
+ {% endif %}
340
+ {% endif %}
341
+ {% endfor %}
342
+ </ul>
343
+ {% endif %}
344
+ {% endraw %}
345
+ ```
346
+
347
+ ## Best Practices and Tips
348
+
349
+ 1. **Consistent Front Matter**: Establish a template for front matter across your documents. This ensures consistency and makes it easier to implement site-wide features.
350
+
351
+ 2. **Versioning Documentation**: For software documentation, consider using Git branches for different versions. You can then build separate sites for each version.
352
+
353
+ 3. **Handling Images and Assets**: Store images in an `assets` folder within each collection. This keeps your content organized and makes it easy to move or refactor sections.
354
+
355
+ ## Case Study: Refactoring an Existing Documentation Site
356
+
357
+ Let's say we have an existing documentation site with a flat structure, where all documents are in the `_posts` folder. Here's how we might refactor it:
358
+
359
+ Before:
360
+ ```
361
+ _posts/
362
+ 2023-01-01-installation.md
363
+ 2023-01-02-quick-start.md
364
+ 2023-01-03-advanced-features.md
365
+ 2023-01-04-api-reference.md
366
+ 2023-01-05-troubleshooting.md
367
+ ```
368
+
369
+ After:
370
+ ```
371
+ _getting_started/
372
+ installation.md
373
+ quick-start.md
374
+ _user_guide/
375
+ advanced-features.md
376
+ _api_reference/
377
+ index.md
378
+ _troubleshooting/
379
+ common-issues.md
380
+ ```
381
+
382
+ This refactoring, combined with the Jekyll Collection Pages plugin configuration we discussed earlier, results in:
383
+
384
+ - Clearer content organization
385
+ - Automatically generated category pages
386
+ - Easier navigation with breadcrumbs and dynamic sidebar
387
+ - Improved search functionality
388
+
389
+ ## Conclusion
390
+
391
+ By leveraging Jekyll's collection feature and the power of the Jekyll Collection Pages plugin, you can create a documentation site that's not only comprehensive but also user-friendly and easy to maintain. The key takeaways are:
392
+
393
+ 1. Plan your content structure carefully
394
+ 2. Use collections to organize your content logically
395
+ 3. Implement search to help users find information quickly
396
+ 4. Utilize the Jekyll Collection Pages plugin to automate category page creation and enhance organization
397
+ 5. Implement features like breadcrumbs and related content to improve navigation
398
+
399
+ With these strategies in place, your Jekyll documentation site will be well-structured, easily navigable, and primed for growth. Happy documenting!
@@ -0,0 +1,89 @@
1
+ ---
2
+ title: "Linking Obsidian and Jekyll"
3
+ date: 2024-08-02
4
+ author: Allison Thackston
5
+ image: /assets/img/post-img-1.png
6
+ tags: [jekyll, obsidian, collections, symlinks, drafts]
7
+ ---
8
+
9
+ As a long-time Obsidian user, I've fallen in love with its flexibility, linking capabilities, and the sheer joy of connecting ideas across my personal knowledge base. The way Obsidian allows me to create, organize, and interlink my thoughts is nothing short of revolutionary for my workflow. But there's been one persistent itch I've wanted to scratch: how can I easily share select parts of my Obsidian vault with the world?
10
+
11
+ Enter Jekyll, the static site generator that's been a staple for developers and bloggers alike. Jekyll's power in creating fast, efficient websites is undeniable. However, the traditional Jekyll setup, with its focus on the _posts directory and specific naming conventions, always felt at odds with my Obsidian workflow. The thought of manually renaming files, adjusting front matter, and maintaining two separate systems for my notes was, frankly, exhausting.
12
+
13
+ What I needed was a bridge between these two worlds - a way to harness Obsidian's note-taking prowess and Jekyll's publishing capabilities without compromising either. I wanted to write in Obsidian as I always have, with my preferred file names and organization, and then seamlessly publish select notes to my Jekyll site without any file juggling or renaming gymnastics.
14
+
15
+ That's where this setup comes in. By leveraging Jekyll collections, smart use of symlinks, and the power of the `jekyll-collection-pages` plugin, we can create a harmonious workflow that respects the Obsidian structure while unlocking Jekyll's publishing potential.
16
+
17
+
18
+ ## Creating the Symlink
19
+
20
+ 1. Open your terminal.
21
+ 2. Navigate to your Jekyll site's root directory.
22
+ 3. Create a symlink from your Obsidian vault to a Jekyll collection:
23
+
24
+ ```bash
25
+ ln -s /path/to/your/obsidian/vault /path/to/your/jekyll/_articles
26
+ ```
27
+
28
+ Replace `/path/to/your/obsidian/vault` with the actual path to your Obsidian vault, and `/path/to/your/jekyll/_articles` with the path where you want the collection in your Jekyll site.
29
+
30
+ ## Setting Up the Collection
31
+
32
+ 1. In your Jekyll `_config.yml`, add:
33
+
34
+ ```yaml
35
+ collections:
36
+ articles:
37
+ output: true
38
+ ```
39
+
40
+ 2. Create a default layout for articles in `_layouts/article.html`.
41
+
42
+ ## Enabling Tags
43
+
44
+ 1. In `_config.yml`, add:
45
+
46
+ ```yaml
47
+ collection_pages:
48
+ - collection: articles
49
+ field: tags
50
+ path: tags
51
+ layout: tag_layout.html
52
+ ```
53
+
54
+ 2. Create `_layouts/tag_layout.html` for your tag pages.
55
+
56
+ ## Managing Drafts
57
+
58
+ 1. In `_config.yml`, add a default front matter for articles:
59
+
60
+ ```yaml
61
+ defaults:
62
+ - scope:
63
+ path: ""
64
+ type: "articles"
65
+ values:
66
+ layout: "article"
67
+ published: false
68
+ ```
69
+
70
+ 2. In Obsidian, add to your note's front matter to publish:
71
+
72
+ ```yaml
73
+ ---
74
+ published: true
75
+ ---
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ 1. Write your notes in Obsidian as usual.
81
+ 2. Add tags in Obsidian using `#tag` syntax or in the front matter.
82
+ 3. When ready to publish, add `published: true` to the note's front matter.
83
+ 4. Build your Jekyll site – only published articles will appear.
84
+
85
+ This setup allows you to seamlessly use Obsidian for note-taking while leveraging Jekyll's powerful publishing features. The Jekyll Collection Pages plugin handles tag organization, making your content easily navigable.
86
+
87
+ Remember to gitignore the symlinked directory to avoid committing your entire Obsidian vault!
88
+
89
+ Happy writing and publishing!
data/demo/_config.yml ADDED
@@ -0,0 +1,83 @@
1
+ theme: jekyll-theme-profile
2
+ style: topbar
3
+ title: Jekyll Collection Pages plugin
4
+ repository: PrimerPages/jekyll-collection-pages
5
+ author: PrimerPages
6
+ description: "A plugin for creating index pages for a collection."
7
+ image: /assets/img/jekyll-collection-pages-preview.png
8
+
9
+ #profile info
10
+ repo_info: false
11
+ user_metadata: false
12
+ user_image: /assets/img/jekyll-collection-pages.png
13
+ profile_link: false
14
+
15
+ collections:
16
+ docs:
17
+ output: true
18
+ sort_by: order
19
+ articles:
20
+ output: true
21
+
22
+ defaults:
23
+ - scope:
24
+ path: "" # an empty string here means all files in the project
25
+ type: "articles"
26
+ values:
27
+ layout: "post"
28
+ image: /assets/img/default.png # The default image used for social and posts.
29
+ permalink: /articles/:path:output_ext
30
+ - scope:
31
+ path: "" # an empty string here means all files in the project
32
+ type: "docs"
33
+ values:
34
+ layout: "docs"
35
+ image: /assets/img/default.png # The default image used for social and posts.
36
+ permalink: /docs/:path:output_ext
37
+ toc: true
38
+
39
+ links:
40
+ - name: Docs
41
+ url: /docs
42
+ thumbnail: /assets/img/docs.png
43
+ - name: Articles
44
+ url: /articles
45
+ thumbnail: /assets/img/articles.png
46
+
47
+ collection_pages:
48
+ - collection: docs
49
+ field: category
50
+ path: /docs
51
+ layout: collection_layout.html
52
+ paginate: 6
53
+ - collection: articles
54
+ field: tags
55
+ path: /tags
56
+ layout: tags.html
57
+ paginate: 3
58
+
59
+ ####################
60
+ # jekyll-paginate settings
61
+ paginate: 6 # The number of posts to show per page of pagination of blog posts
62
+ paginate_path: "/blog/page:num"
63
+
64
+ ###################
65
+ # Theme tag settings related
66
+ tag_page_dir: tags
67
+ related_by: "tags or categories"
68
+
69
+ ###################
70
+ # jekyll-relative-links settings
71
+ relative_links:
72
+ enabled: true
73
+ collections: true
74
+
75
+ plugins:
76
+ - jekyll-paginate
77
+ - jekyll-collection-pages
78
+ - jekyll-github-metadata
79
+ - jekyll-octicons
80
+ - jekyll-relative-links
81
+ - jekyll-seo-tag
82
+ - jekyll-toc
83
+ - jemoji
@@ -0,0 +1,113 @@
1
+ ---
2
+ title: "Configuration guide"
3
+ category: "Reference"
4
+ description: "Reference for every collection_pages option, defaults, and validation tips."
5
+ order: 3
6
+ ---
7
+
8
+ This guide describes the configuration options available in `jekyll-collection-pages` and how they interact. Use it as the single reference while wiring the plugin into your site.
9
+
10
+ ## Overview
11
+
12
+ Add a `collection_pages` entry to `_config.yml`. Each entry targets one collection and one front-matter field:
13
+
14
+ ```yaml
15
+ collection_pages:
16
+ - collection: docs
17
+ field: category
18
+ path: docs/category
19
+ layout: category_layout.html
20
+ paginate: 6
21
+ ```
22
+
23
+ You can declare multiple collections or multiple fields for the same collection by adding more entries to the array:
24
+
25
+ ```yaml
26
+ collections:
27
+ docs:
28
+ output: true
29
+ articles:
30
+ output: true
31
+
32
+ collection_pages:
33
+ - collection: docs
34
+ field: category
35
+ path: docs/category
36
+ layout: category_layout.html
37
+ paginate: 6
38
+ - collection: articles
39
+ field: tags
40
+ path: articles/tags
41
+ layout: tags_layout.html
42
+ paginate: 10
43
+ ```
44
+
45
+ If you only need a single entry, `collection_pages` can also be a hash (the plugin normalises it internally). The array form keeps things consistent once you add more targets.
46
+
47
+ Each `path` above is treated as a template—directory values automatically expand to `docs/<section>/categories/:field/page:num/index.html`. To switch to file-style permalinks, include the placeholders yourself, e.g. `docs/getting-started/categories/:field-page:num.html`.
48
+
49
+ ## Configuration options
50
+
51
+ ### `collection`
52
+
53
+ - Type: `String`
54
+ - Required: ✔
55
+ - Description: Collection label from your `collections` configuration.
56
+
57
+ ### `field`
58
+
59
+ - Type: `String`
60
+ - Required: ✔
61
+ - Description: Front-matter key used to group documents. Supports scalar values (e.g. `"category"`) and array values (e.g. `"tags"`).
62
+
63
+ Make sure every document you expect to index sets this field. When the field holds an array, the plugin creates one page per value.
64
+
65
+ ### `path`
66
+
67
+ - Type: `String`
68
+ - Required: ✔
69
+ - Description: Path template relative to the site source. It must contain exactly one `:field` placeholder (replaced with the slugified field value) and one `:num` placeholder (replaced with the page number). When you omit placeholders in a directory-style path, the plugin automatically appends them as `<path>/:field/page:num/index.html`. When you provide a filename (ends in `.html`/`.htm`), you must include both placeholders yourself. Leading/trailing slashes are stripped either way.
70
+
71
+ Rules enforced by the generator:
72
+
73
+ - `:field` must appear before `:num`, and they cannot be in the same path segment.
74
+ - Paths ending in `.html`/`.htm` must include both placeholders already.
75
+ - Leaving `path` blank defaults to `<collection>/:field/page:num/index.html`.
76
+
77
+ ### `layout`
78
+
79
+ - Type: `String`
80
+ - Required: ✖ (default: `collection_layout.html`)
81
+ - Description: Layout file in `_layouts/` to render the generated page.
82
+
83
+ The plugin copies `page.posts`, `page.tag`, and optional `page.paginator` into the layout context.
84
+
85
+ ### `paginate`
86
+
87
+ - Type: `Integer`
88
+ - Required: ✖
89
+ - Description: When present and positive, splits the documents into pages of the given size. Pagination behaves like Jekyll’s built-in paginator (`page.paginator` exposes `page`, `total_pages`, `previous_page_path`, `next_page_path`, etc.) and the generated paths already include the tag directory (e.g. `docs/category/getting-started/`, `docs/category/getting-started/page2.html`), so piping them through `relative_url` yields working links.
90
+
91
+ Set `paginate` to `nil`, omit the key, or use a non-positive number to render a single page per label. Non-numeric values raise an error during the build, so typos like `"ten"` fail fast.
92
+
93
+ ## Generated data
94
+
95
+ At build time the plugin exports `site.data.collection_pages[collection_name][field]`, which contains:
96
+
97
+ - `template` → the full sanitized template used for creating pages with placeholders intact. Directory-style values from `_config.yml` are auto-appended with `:field/page:num/index.html`. (e.g. `/docs/category/:field/page:num/index.html`)
98
+ - `permalink` → the sanitized template for the index with placeholders intact (e.g. `/docs/category/:field/`)
99
+ - `pages` → documents grouped by label (`{ label => [documents...] }`)
100
+ - `labels`: metadata describing the generated index pages
101
+
102
+ Use `pages` to feed existing includes, and `labels[label].index.url` when you need the generated index URL.
103
+
104
+ See the [Generated data reference](generated-data.md) for usage patterns and Liquid snippets.
105
+
106
+ ## Validation tips
107
+
108
+ - Ensure the target collection has `output: true`, otherwise links from index pages may 404.
109
+ - Double-check that the `field` exists in every document; documents missing the field are skipped.
110
+ - Use `bundle exec jekyll build --trace` with `JEKYLL_LOG_LEVEL=debug` to see the plugin’s log output (e.g. total pages generated).
111
+ - Inspect `site.data.collection_pages` in a rendered page (`{% raw %}{{ site.data.collection_pages | jsonify }}{% endraw %}`) when debugging Liquid loops.
112
+
113
+ Ready to dive deeper? Explore the [examples](examples.md) for real-world configurations and the [layout recipes](layout-recipes.md) to customise the rendered pages.