From c09b09c7af5a0cd4da4779f1b89d4585ed404cfa Mon Sep 17 00:00:00 2001 From: Mahdi Pourismaiel Date: Tue, 4 Aug 2020 06:01:01 +0430 Subject: [PATCH 1/5] Add new global variable, hide --- layouts/partials/helpers/fragments.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/partials/helpers/fragments.html b/layouts/partials/helpers/fragments.html index fdbd6987..b6296a93 100644 --- a/layouts/partials/helpers/fragments.html +++ b/layouts/partials/helpers/fragments.html @@ -181,7 +181,7 @@ {{- $directory_same_name := in ($page_scratch.Get "fragments_directory_name") (printf "%s%s/" $root.File.Dir (replace $name ".md" "")) -}} {{- if and (not .Params.disabled) (isset .Params "fragment") (not $directory_same_name) -}} {{- if or $is_404 (ne .Params.fragment "404") -}} - {{- if and (eq .Params.fragment "config") (not (where ($page_scratch.Get "page_config") ".Name" $name)) -}} + {{- if and (eq .Params.fragment "config") (not (where ($page_scratch.Get "page_config") ".Name" $name)) (ne .Params.hide true) -}} {{- $page_scratch.Add "page_config" . -}} {{- else if not (where ($page_scratch.Get "page_fragments") ".Name" $name) -}} {{- $page_scratch.Add "page_fragments" . -}} From d6ae1d0b3c1027fc477c78be95c1edb6fbe2f7ff Mon Sep 17 00:00:00 2001 From: Mahdi Pourismaiel Date: Tue, 4 Aug 2020 06:01:16 +0430 Subject: [PATCH 2/5] Update documentation and add hide global variable --- exampleSite/content/docs/fragments/content.md | 2 ++ exampleSite/content/docs/global-variables/content.md | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/exampleSite/content/docs/fragments/content.md b/exampleSite/content/docs/fragments/content.md index d3fb8a59..57f44031 100644 --- a/exampleSite/content/docs/fragments/content.md +++ b/exampleSite/content/docs/fragments/content.md @@ -84,6 +84,8 @@ All fragments within this directory are rendered on all pages by default. To overwrite a global fragment create a per page fragment with the same filename. This would overwrite the global one. +Also in order to hide a global fragment in a specific page or section, you can use the [`hide` global variable]({{< ref "global-variables">}}/#hide). + Aside from the `content/_global/` directory, you can create `_global/` directory in any section's directory (`content/[section]/_global/`). Each section can have global fragments and if there are multiple fragments with the same name, the fragment closest to the page would override the others. diff --git a/exampleSite/content/docs/global-variables/content.md b/exampleSite/content/docs/global-variables/content.md index a58ec87b..f7fcec41 100644 --- a/exampleSite/content/docs/global-variables/content.md +++ b/exampleSite/content/docs/global-variables/content.md @@ -85,3 +85,15 @@ Action/clickable URL of the image or the icon. *type: string* If `asset.image` is set, `text` will be used as alternative text (alt-text) of the image. + +#### disable +*type: boolean* + +If set to `true`, Syna will not register the fragment. This is useful for drafting fragments. + +**NOTE:** `disable` doesn't register the fragment at all. This means you can not remove a global fragment in a specific page by a duplicate disabled fragment. In order to hide a global fragment in a page, use [`hide`](#hide). + +#### hide +*type: boolean* + +If set to `true`, Syna will not call the fragment and will hide it. Useful for hiding a global fragment in the page. For more information, please checkout [global fragments]({{< ref "docs/fragments">}}/#global-fragments). From 9715b732da858191d9c3bd2bc71dc0c0ffb5924b Mon Sep 17 00:00:00 2001 From: Mahdi Pourismaiel Date: Tue, 4 Aug 2020 06:10:47 +0430 Subject: [PATCH 3/5] Fix hide parameter --- layouts/partials/helpers/fragments-renderer.html | 2 +- layouts/partials/helpers/fragments.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/layouts/partials/helpers/fragments-renderer.html b/layouts/partials/helpers/fragments-renderer.html index c9ba7ac7..ff381b64 100644 --- a/layouts/partials/helpers/fragments-renderer.html +++ b/layouts/partials/helpers/fragments-renderer.html @@ -8,7 +8,7 @@ {{- range sort ($page_scratch.Get "page_fragments" | default slice) "Params.weight" -}} {{/* If a fragment contains a slot variable in it's frontmatter it should not be rendered on the page. It would be later handled by the slot helper. */}} - {{- if and (not (isset .Params "slot")) (ne .Params.slot "") -}} + {{- if and (not (isset .Params "slot")) (ne .Params.slot "") (ne .Params.hide true) -}} {{/* Cleanup .Name to be more useful within fragments */}} {{- $page_scratch.Set "tmp_name" (cond (eq $page .) .File.BaseFileName (strings.TrimSuffix ".md" (replace .Name "/index.md" ""))) -}} {{- if ne $page.Language nil -}} diff --git a/layouts/partials/helpers/fragments.html b/layouts/partials/helpers/fragments.html index b6296a93..2d2d22ed 100644 --- a/layouts/partials/helpers/fragments.html +++ b/layouts/partials/helpers/fragments.html @@ -181,7 +181,7 @@ {{- $directory_same_name := in ($page_scratch.Get "fragments_directory_name") (printf "%s%s/" $root.File.Dir (replace $name ".md" "")) -}} {{- if and (not .Params.disabled) (isset .Params "fragment") (not $directory_same_name) -}} {{- if or $is_404 (ne .Params.fragment "404") -}} - {{- if and (eq .Params.fragment "config") (not (where ($page_scratch.Get "page_config") ".Name" $name)) (ne .Params.hide true) -}} + {{- if and (eq .Params.fragment "config") (not (where ($page_scratch.Get "page_config") ".Name" $name)) (ne .Params.hide) -}} {{- $page_scratch.Add "page_config" . -}} {{- else if not (where ($page_scratch.Get "page_fragments") ".Name" $name) -}} {{- $page_scratch.Add "page_fragments" . -}} From 610832d9a608f4d675b2f3300f4e72a78ee90788 Mon Sep 17 00:00:00 2001 From: Mahdi Pourismaiel Date: Tue, 4 Aug 2020 06:10:58 +0430 Subject: [PATCH 4/5] Add tests in fragment fallthrough dev page for hide variable --- .../content/dev/fragment-fallthrough/_global/config.md | 9 +++++++++ .../content/dev/fragment-fallthrough/_global/hidden.md | 5 +++++ .../content/dev/fragment-fallthrough/_index/config.md | 4 ++++ .../content/dev/fragment-fallthrough/_index/content.md | 2 +- .../content/dev/fragment-fallthrough/_index/hidden.md | 6 ++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 exampleSite/content/dev/fragment-fallthrough/_global/config.md create mode 100644 exampleSite/content/dev/fragment-fallthrough/_global/hidden.md create mode 100644 exampleSite/content/dev/fragment-fallthrough/_index/config.md create mode 100644 exampleSite/content/dev/fragment-fallthrough/_index/hidden.md diff --git a/exampleSite/content/dev/fragment-fallthrough/_global/config.md b/exampleSite/content/dev/fragment-fallthrough/_global/config.md new file mode 100644 index 00000000..a54b7181 --- /dev/null +++ b/exampleSite/content/dev/fragment-fallthrough/_global/config.md @@ -0,0 +1,9 @@ ++++ +fragment = "config" + +[[config]] + type = "js" + html = """""" ++++ diff --git a/exampleSite/content/dev/fragment-fallthrough/_global/hidden.md b/exampleSite/content/dev/fragment-fallthrough/_global/hidden.md new file mode 100644 index 00000000..f1f9857d --- /dev/null +++ b/exampleSite/content/dev/fragment-fallthrough/_global/hidden.md @@ -0,0 +1,5 @@ ++++ +fragment = "content" +weight = 110 +title = "If you're seeing this, hide and fallthrough don't work" ++++ diff --git a/exampleSite/content/dev/fragment-fallthrough/_index/config.md b/exampleSite/content/dev/fragment-fallthrough/_index/config.md new file mode 100644 index 00000000..70b94df7 --- /dev/null +++ b/exampleSite/content/dev/fragment-fallthrough/_index/config.md @@ -0,0 +1,4 @@ ++++ +fragment = "config" +hide = true ++++ diff --git a/exampleSite/content/dev/fragment-fallthrough/_index/content.md b/exampleSite/content/dev/fragment-fallthrough/_index/content.md index 71b53c33..16e48994 100644 --- a/exampleSite/content/dev/fragment-fallthrough/_index/content.md +++ b/exampleSite/content/dev/fragment-fallthrough/_index/content.md @@ -1,7 +1,7 @@ +++ fragment = "content" weight = 100 -title = "Content fragment from Page" +title = "Content fragment from Page, this text should be black" +++ This is loaded from the page, overriding the globals of current section. Seems diff --git a/exampleSite/content/dev/fragment-fallthrough/_index/hidden.md b/exampleSite/content/dev/fragment-fallthrough/_index/hidden.md new file mode 100644 index 00000000..391713bb --- /dev/null +++ b/exampleSite/content/dev/fragment-fallthrough/_index/hidden.md @@ -0,0 +1,6 @@ ++++ +fragment = "content" +weight = 110 +title = "If you're seeing this, hide doesn't work" +hide = true ++++ From 8257e3ec770133889f8d081970789158c7bc6733 Mon Sep 17 00:00:00 2001 From: Mahdi Pourismaiel Date: Fri, 7 Aug 2020 12:56:24 +0430 Subject: [PATCH 5/5] Update according to suggestions in PR Co-authored-by: Michael Grosser --- exampleSite/content/docs/fragments/content.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exampleSite/content/docs/fragments/content.md b/exampleSite/content/docs/fragments/content.md index 57f44031..cdb59483 100644 --- a/exampleSite/content/docs/fragments/content.md +++ b/exampleSite/content/docs/fragments/content.md @@ -84,7 +84,7 @@ All fragments within this directory are rendered on all pages by default. To overwrite a global fragment create a per page fragment with the same filename. This would overwrite the global one. -Also in order to hide a global fragment in a specific page or section, you can use the [`hide` global variable]({{< ref "global-variables">}}/#hide). +In order to hide a global fragment in a specific page or section, you can use the [`hide` global variable]({{< ref "global-variables">}}/#hide). Aside from the `content/_global/` directory, you can create `_global/` directory in any section's directory (`content/[section]/_global/`). Each section can have global fragments and if there are multiple fragments with the same name, the fragment closest to the page would override the others.