From 72555568194478cbfa71643401b5158c7091f8eb Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 11 Jan 2017 16:03:51 -0700 Subject: [PATCH 1/5] Fixed issue with multi-lang site caching non-lang specific pages for all langs #1211 --- CHANGELOG.md | 1 + system/src/Grav/Common/Page/Page.php | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42e9505d0..ce2d19358 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * Fix renaming the folder name if the page, in the default language, had a custom slug set in its header * Fixed issue with `Content-Encoding: none`. It should really be `Content-Encoding: identity` instead * Fixed broken `hash` method on page modifications detection + * Fixed issue with multi-lang pages not caching independently without unique `.md` file [#1211](https://github.com/getgrav/grav/issues/1211) # v1.1.12 ## 12/26/2016 diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 662b361c3..95da4050c 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -1687,7 +1687,10 @@ class Page public function id($var = null) { if ($var !== null) { - $this->id = $var; + // store unique per language + $active_lang = Grav::instance()['language']->getLanguage() ?: ''; + $id = $active_lang . $var; + $this->id = $id; } return $this->id; From e492fbde21b6d671c7d9913ee5c155317bd49a05 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 12 Jan 2017 06:40:51 -0700 Subject: [PATCH 2/5] Hash added to blueprints --- CHANGELOG.md | 9 +++++---- system/blueprints/config/system.yaml | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2d19358..13ac3606e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 1. [](#improved) * Several improvements to aid theme development [#232](https://github.com/getgrav/grav/pull/1232) + * Added `hash` cache check option and made dropdown more descriptive [Admin #923](https://github.com/getgrav/grav-plugin-admin/issues/923) 1. [](#bugfix) * Fixed cross volume file system operations [#635](https://github.com/getgrav/grav/issues/635) * Fix issue with pages folders validation not accepting uppercase letters @@ -36,8 +37,8 @@ * Fixed case where extracting a package would cause an error during rename * Fix issue with using `Yaml::parse` direcly on a filename, now deprecated * Add pattern for frontend validation of folder slugs [#891](https://github.com/getgrav/grav-plugin-admin/issues/891) - * Fix issue with Inflector when translation is disabled [https://github.com/getgrav/grav-plugin-simplesearch/issues/87](https://github.com/getgrav/grav-plugin-simplesearch/issues/87) - * Explicitly expose `array_unique` Twig filter [https://github.com/getgrav/grav-plugin-admin/issues/897](https://github.com/getgrav/grav-plugin-admin/issues/897) + * Fix issue with Inflector when translation is disabled [SimpleSearch #87](https://github.com/getgrav/grav-plugin-simplesearch/issues/87) + * Explicitly expose `array_unique` Twig filter [Admin #897](https://github.com/getgrav/grav-plugin-admin/issues/897) # v1.1.9 ## 12/13/2016 @@ -85,7 +86,7 @@ * Add 2 new language values for French [#1174](https://github.com/getgrav/grav/issues/1174) 1. [](#bugfix) * Fixed issue when we have a meta file without corresponding media [#1179](https://github.com/getgrav/grav/issues/1179) - * Update class namespace for Admin class [#874](https://github.com/getgrav/grav-plugin-admin/issues/874) + * Update class namespace for Admin class [Admin #874](https://github.com/getgrav/grav-plugin-admin/issues/874) # v1.1.9-rc.1 ## 11/09/2016 @@ -148,7 +149,7 @@ 1. [](#bugfix) * Fixed missing `progress` method in the DirectInstall Command * `Response` class now handles better unsuccessful requests such as 404 and 401 - * Fixed saving of `external` page types [admin #789](https://github.com/getgrav/grav-plugin-admin/issues/789) + * Fixed saving of `external` page types [Admin #789](https://github.com/getgrav/grav-plugin-admin/issues/789) * Fixed issue deleting parent folder of folder with `param_sep` in the folder name [admin #796](https://github.com/getgrav/grav-plugin-admin/issues/796) * Fixed an issue with streams in `bin/plugin` * Fixed `jpeg` file format support in Media diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index a55c1e1de..34a9ec51b 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -461,14 +461,15 @@ form: cache.check.method: type: select - size: small + size: medium classes: fancy label: PLUGIN_ADMIN.CACHE_CHECK_METHOD help: PLUGIN_ADMIN.CACHE_CHECK_METHOD_HELP options: - file: File - folder: Folder - none: None + file: Markdown file + media timestamps + folder: Folder timestamps + hash: All files timestamps + none: No timestamp checking cache.driver: type: select From 9ebff2287cb238182a0d05ce1c3f0da275607c0e Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 12 Jan 2017 10:59:05 -0700 Subject: [PATCH 3/5] =?UTF-8?q?Fixed=20an=20error=20in=20the=20=E2=80=98fi?= =?UTF-8?q?le=E2=80=99=20type=20description?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/blueprints/config/system.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 34a9ec51b..56066e3f9 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -466,7 +466,7 @@ form: label: PLUGIN_ADMIN.CACHE_CHECK_METHOD help: PLUGIN_ADMIN.CACHE_CHECK_METHOD_HELP options: - file: Markdown file + media timestamps + file: Markdown + Yaml file timestamps folder: Folder timestamps hash: All files timestamps none: No timestamp checking From 759ba5143f23e4e755a72b80bb934c54fccae8aa Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 12 Jan 2017 11:51:12 -0700 Subject: [PATCH 4/5] Added ability to never cache twig. This makes it possible to cache content, but always process twig. Useful for regular but especially modular pages. (#1244) --- system/blueprints/config/system.yaml | 11 +++++ system/blueprints/pages/default.yaml | 24 +++++++++++ system/config/system.yaml | 1 + system/src/Grav/Common/Page/Page.php | 64 +++++++++++++++++++--------- 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/system/blueprints/config/system.yaml b/system/blueprints/config/system.yaml index 56066e3f9..d8b0a24a6 100644 --- a/system/blueprints/config/system.yaml +++ b/system/blueprints/config/system.yaml @@ -244,6 +244,17 @@ form: validate: type: bool + pages.never_cache_twig: + type: toggle + label: PLUGIN_ADMIN.NEVER_CACHE_TWIG + help: PLUGIN_ADMIN.NEVER_CACHE_TWIG_HELP + highlight: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + pages.frontmatter.process_twig: type: toggle label: PLUGIN_ADMIN.FRONTMATTER_PROCESS_TWIG diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index 5fb9ab232..4fd60722d 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -225,6 +225,30 @@ form: twig: Twig use: keys + header.twig_first: + type: toggle + toggleable: true + label: PLUGIN_ADMIN.TWIG_FIRST + help: PLUGIN_ADMIN.TWIG_FIRST_HELP + highlight: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + + header.never_cache_twig: + type: toggle + toggleable: true + label: PLUGIN_ADMIN.NEVER_CACHE_TWIG + help: PLUGIN_ADMIN.NEVER_CACHE_TWIG_HELP + highlight: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + header.child_type: type: select toggleable: true diff --git a/system/config/system.yaml b/system/config/system.yaml index 54e4c4781..7f7ba4baf 100644 --- a/system/config/system.yaml +++ b/system/config/system.yaml @@ -36,6 +36,7 @@ pages: markdown: true # Process Markdown twig: false # Process Twig twig_first: false # Process Twig before markdown when processing both on a page + never_cache_twig: false # Only cache content, never cache twig processed in content (incompatible with `twig_first: true`) events: page: true # Enable page level events twig: true # Enable Twig level events diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 95da4050c..013a3ab32 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -572,16 +572,16 @@ class Page $twig_first = isset($this->header->twig_first) ? $this->header->twig_first : $config->get('system.pages.twig_first', true); + // never cache twig means it's always run after content + $never_cache_twig = isset($this->header->never_cache_twig) ? $this->header->never_cache_twig : $config->get('system.pages.never_cache_twig', + false); // if no cached-content run everything - if ($this->content === false || $cache_enable === false) { - $this->content = $this->raw_content; - Grav::instance()->fireEvent('onPageContentRaw', new Event(['page' => $this])); + if ($never_cache_twig) { + if ($this->content === false || $cache_enable === false) { + $this->content = $this->raw_content; + Grav::instance()->fireEvent('onPageContentRaw', new Event(['page' => $this])); - if ($twig_first) { - if ($process_twig) { - $this->processTwig(); - } if ($process_markdown) { $this->processMarkdown(); } @@ -589,21 +589,47 @@ class Page // Content Processed but not cached yet Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this])); - } else { - if ($process_markdown) { - $this->processMarkdown(); - } - - // Content Processed but not cached yet - Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this])); - - if ($process_twig) { - $this->processTwig(); + if ($cache_enable) { + $this->cachePageContent(); } } - if ($cache_enable) { - $this->cachePageContent(); + if ($process_twig) { + $this->processTwig(); + } + + } else { + if ($this->content === false || $cache_enable === false) { + $this->content = $this->raw_content; + Grav::instance()->fireEvent('onPageContentRaw', new Event(['page' => $this])); + + if ($twig_first) { + if ($process_twig) { + $this->processTwig(); + } + if ($process_markdown) { + $this->processMarkdown(); + } + + // Content Processed but not cached yet + Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this])); + + } else { + if ($process_markdown) { + $this->processMarkdown(); + } + + // Content Processed but not cached yet + Grav::instance()->fireEvent('onPageContentProcessed', new Event(['page' => $this])); + + if ($process_twig) { + $this->processTwig(); + } + } + + if ($cache_enable) { + $this->cachePageContent(); + } } } From 3cffe74965dc6474774b88773ee20266039f6344 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 12 Jan 2017 11:55:10 -0700 Subject: [PATCH 5/5] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ac3606e..db83741fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.1.13 ## xx/xx/201x +1. [](#new) + * Added new `never_cache_twig` page option in `system.yaml` and frontmatter. Allows dynamic Twig logic in regular and modular Twig templates [#1244](https://github.com/getgrav/grav/pull/1244) 1. [](#improved) * Several improvements to aid theme development [#232](https://github.com/getgrav/grav/pull/1232) * Added `hash` cache check option and made dropdown more descriptive [Admin #923](https://github.com/getgrav/grav-plugin-admin/issues/923)