From 78aca49b03dd23e8d491844a45f53a7eaaa5f1eb Mon Sep 17 00:00:00 2001 From: chrisrhymes Date: Wed, 31 Jul 2024 20:21:06 +0100 Subject: [PATCH] Allow custom collection name for products --- _includes/cookie-banner.html | 6 +++--- _layouts/product-category.html | 6 +++++- docs/products/category-page.md | 17 ++++++++++++++++- docs/products/product-pages.md | 10 +++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/_includes/cookie-banner.html b/_includes/cookie-banner.html index 94dcb72bd..8263641b3 100644 --- a/_includes/cookie-banner.html +++ b/_includes/cookie-banner.html @@ -23,13 +23,13 @@ {% if site.google_analytics %} consentGrantedAdStorage(); {% endif %} - Cookies.set('showCookieBanner', 'false', { expires: 7, path: '/' }); - Cookies.set('cookiesAccepted', 'true', {expires: 7, path: '/'}); + Cookies.set('showCookieBanner', 'false', { expires: 365, path: '/' }); + Cookies.set('cookiesAccepted', 'true', {expires: 365, path: '/'}); toggleCookieBanner(); } function rejectCookies() { - Cookies.set('showCookieBanner', 'false', { expires: 7, path: '/' }); + Cookies.set('showCookieBanner', 'false', { expires: 365, path: '/' }); toggleCookieBanner(); } diff --git a/_layouts/product-category.html b/_layouts/product-category.html index 25f430711..bcf397663 100644 --- a/_layouts/product-category.html +++ b/_layouts/product-category.html @@ -7,7 +7,11 @@ {{ page.content }} - {% assign sorted_products = site.products | sort: page.sort %} + {% if page.collection %} + {% assign sorted_products = site.[page.collection] | sort: page.sort %} + {% else %} + {% assign sorted_products = site.products | sort: page.sort %} + {% endif %} {% for product in sorted_products %}
diff --git a/docs/products/category-page.md b/docs/products/category-page.md index 795d65d2b..f8cf6cedf 100644 --- a/docs/products/category-page.md +++ b/docs/products/category-page.md @@ -21,4 +21,19 @@ show_sidebar: false sort: title ``` -[View example Category page](/bulma-clean-theme/products/) \ No newline at end of file +[View example Category page](/bulma-clean-theme/products/) + +## Customising the collection + +To use a different collection than `products`, set the collection name in the category page's front matter. + +The below example uses a collection called `books`. + +```yaml +title: Books +subtitle: Check out our range of books +layout: product-category +show_sidebar: false +sort: title +collection: books +``` \ No newline at end of file diff --git a/docs/products/product-pages.md b/docs/products/product-pages.md index 126d6f1f8..db3d850f3 100644 --- a/docs/products/product-pages.md +++ b/docs/products/product-pages.md @@ -9,7 +9,11 @@ toc: true ## Products Directory -Start by creating a `_products` directory to hold your product pages. +The default collection name for products is `products`, so create a `_products` directory to hold your product pages. + +## Custom Collection Directory + +You can override the default and create a folder with your own collection name. For example, using a collection of `books` would require you to create a folder called `_books`. ## Product Pages @@ -52,3 +56,7 @@ collections: ``` You can also set default product page values here if you like, such as the layout or image. + +{% include notification.html message="If you use a custom collection name then update `products` to your custom collection name. In the example above for the `_books` folder use `books` as the collection name." %} + +For more information on collections, please refer to the [Jekyll documentation](https://jekyllrb.com/docs/collections/). \ No newline at end of file