From e0d80ef29e1c847caa63e2d232b032317f93d132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Brunet?= Date: Wed, 19 May 2021 01:02:51 +0200 Subject: [PATCH] Make site settings editable from CMS --- .eleventy.js | 5 +---- src/_data/site.js | 9 --------- src/_data/site.json | 8 ++++++++ src/_includes/components/footer.njk | 2 +- src/admin/config.yml | 20 +++++++++++++++++--- 5 files changed, 27 insertions(+), 17 deletions(-) delete mode 100644 src/_data/site.js create mode 100644 src/_data/site.json diff --git a/.eleventy.js b/.eleventy.js index 63a88bf..1c0cf75 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -42,10 +42,6 @@ module.exports = config => { return util.inspect(value); }); - config.addFilter('dateToYear', function (date) { - return date.getFullYear(); - }); - config.addFilter('noEmoji', function(value) { return value.replace(emojiRegex, '').trim(); }); @@ -90,6 +86,7 @@ module.exports = config => { } config.addNunjucksAsyncShortcode('recipeimage', imageShortcode); + config.addShortcode('year', () => `${new Date().getFullYear()}`); return { dir: { diff --git a/src/_data/site.js b/src/_data/site.js deleted file mode 100644 index a34a39b..0000000 --- a/src/_data/site.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = { - name: "My Online Cookbook", - metaDescription: "The online cookbook of John Doe", - author: "John Doe", - buildTime: new Date(), - primaryColor: "#ffdb70", - secondaryColor: "#32816e", - searchLabel: "Find recipes by name or ingredients" -}; \ No newline at end of file diff --git a/src/_data/site.json b/src/_data/site.json new file mode 100644 index 0000000..9781e7e --- /dev/null +++ b/src/_data/site.json @@ -0,0 +1,8 @@ +{ + "name": "My Online Cookbook", + "metaDescription": "The online cookbook of John Doe", + "author": "John Doe", + "primaryColor": "#ffdb70", + "secondaryColor": "#32816e", + "searchLabel": "Find recipes by name or ingredients" +} \ No newline at end of file diff --git a/src/_includes/components/footer.njk b/src/_includes/components/footer.njk index 733aa58..6560791 100644 --- a/src/_includes/components/footer.njk +++ b/src/_includes/components/footer.njk @@ -1,2 +1,2 @@

Made with My Online Cookbook

-

© {{ site.author }} {{ site.buildTime | dateToYear }}

\ No newline at end of file +

© {{ site.author }} {% year %}

\ No newline at end of file diff --git a/src/admin/config.yml b/src/admin/config.yml index b49ab61..d914aed 100644 --- a/src/admin/config.yml +++ b/src/admin/config.yml @@ -17,7 +17,7 @@ collections: widget: "list" required: false summary: "{{fields.tag}}" - field: {label: "Tag", name: "tag", widget: string} + field: {label: "Tag", name: "tag", widget: "string"} - {label: "Preparation time", name: "time", widget: "string", required: false} - {label: "Number of servings", name: "servings", widget: "number", required: false} - {label: "Source of the recipe", name: "sourceLabel", widget: "string", required: false} @@ -26,5 +26,19 @@ collections: name: "ingredients" widget: "list" summary: "{{fields.ingredient}}" - field: {label: "Ingredient", name: "ingredient", widget: string} - - {label: "Body", name: "body", widget: "markdown"} \ No newline at end of file + field: {label: "Ingredient", name: "ingredient", widget: "string"} + - {label: "Body", name: "body", widget: "markdown"} + - name: "settings" + label: "Settings" + files: + - name: "site" + label: "Site settings" + delete: false + file: "src/_data/site.json" + fields: + - {label: "Site name", name: "name", widget: "string"} + - {label: "Site meta description", name: "metaDescription", widget: "string", hint: "used for SEO"} + - {label: "Author", name: "author", widget: "string"} + - {label: "Primary color", name: "primaryColor", widget: "color", hint: "make sure to choose a color that is light enough to display as a background behind dark text"} + - {label: "Secondary color", name: "secondaryColor", widget: "color", hint: "used for links and focus styles"} + - {label: "Search label", name: "searchLabel", widget: "string"} \ No newline at end of file