From 8a493c77df8737ecda187a8aa245a5b0201277e0 Mon Sep 17 00:00:00 2001 From: otherpaco <27810032+otherpaco@users.noreply.github.com> Date: Thu, 23 Nov 2023 22:46:00 +0100 Subject: [PATCH] feat: add ability to hide posts in blog listing --- exampleSite/content/blog/_index.md | 2 + exampleSite/content/blog/hidden.md | 16 ++++++ exampleSite/content/docs/advanced/_index.md | 1 + .../docs/advanced/blog-as-entrypoint.md | 56 +++++++++++++++++++ layouts/blog/list.html | 4 +- 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 exampleSite/content/blog/hidden.md create mode 100644 exampleSite/content/docs/advanced/blog-as-entrypoint.md diff --git a/exampleSite/content/blog/_index.md b/exampleSite/content/blog/_index.md index b9906659..7d0c5c2c 100644 --- a/exampleSite/content/blog/_index.md +++ b/exampleSite/content/blog/_index.md @@ -8,3 +8,5 @@ title: "Blog" {{< icon name="rss" attributes="height=14" >}} {{< /hextra/hero-badge >}} + +Checkout the unlisted post, find it here `/blog/hidden`. diff --git a/exampleSite/content/blog/hidden.md b/exampleSite/content/blog/hidden.md new file mode 100644 index 00000000..d78611f5 --- /dev/null +++ b/exampleSite/content/blog/hidden.md @@ -0,0 +1,16 @@ +--- +title: Hidden blog entry +date: 2020-01-01 +tags: + - Example + - Guide +excludeSearch: true +hideOnBlog: true +--- + +This post is not listed in the blog overview. + + +## Hidden + +This post is not shown in the overview page of the blog because is has `hideOnBlog: true` in the front matter. diff --git a/exampleSite/content/docs/advanced/_index.md b/exampleSite/content/docs/advanced/_index.md index cdcaed21..f99b8ae1 100644 --- a/exampleSite/content/docs/advanced/_index.md +++ b/exampleSite/content/docs/advanced/_index.md @@ -13,4 +13,5 @@ This section covers some advanced topics of the theme. {{< card link="multi-language" title="Multi-language" icon="translate" >}} {{< card link="customization" title="Customization" icon="pencil" >}} {{< card link="comments" title="Comments System" icon="chat-alt" >}} + {{< card link="blog" title="Blog on starting page" icon="chat-alt" >}} {{< /cards >}} diff --git a/exampleSite/content/docs/advanced/blog-as-entrypoint.md b/exampleSite/content/docs/advanced/blog-as-entrypoint.md new file mode 100644 index 00000000..7cdbc772 --- /dev/null +++ b/exampleSite/content/docs/advanced/blog-as-entrypoint.md @@ -0,0 +1,56 @@ +--- +title: Blog as entrypoint +linkTitle: Blog +--- + +This is a little tutorial how to use the starting page as a blog. + + + +## Directory Structure + +{{< filetree/container >}} + {{< filetree/folder name="content" >}} + {{< filetree/file name="_index.md" >}} + {{< filetree/file name="post-1.md" >}} + {{< filetree/file name="post-2.md" >}} + {{< filetree/file name="about.md" >}} + {{< filetree/folder name="docs" state="open" >}} + {{< filetree/file name="_index.md" >}} + {{< filetree/file name="getting-started.md" >}} + {{< /filetree/folder >}} + {{< /filetree/folder >}} +{{< /filetree/container >}} + +## Make the entrypoint use the blog template + +```yaml {filename="content/_index.md"} +--- +title: My Docs +cascade: + type: blog +--- +``` + +But now the starting page will list all entries, including `/about`. + +## Ignore pages + +```yaml {filename="content/about.md"} +--- +title: My Docs +hideOnBlog: true +--- +``` + +Now the page is still available at `/about` but is not listed as post on the starting page. + +You can hide areas, too. + +```yaml {filename="content/docs/_index.md"} +--- +title: My Docs +cascade: + hideOnBlog: true +--- +``` diff --git a/layouts/blog/list.html b/layouts/blog/list.html index b22de2ec..6fcfbab7 100644 --- a/layouts/blog/list.html +++ b/layouts/blog/list.html @@ -8,6 +8,7 @@

{{ .Title }}

{{ .Content }}
{{ range .Pages.ByDate.Reverse }} + {{- if not .Params.hideOnBlog -}}

{{ .Title }}

{{- if site.Params.blog.list.displayTags -}} @@ -25,9 +26,10 @@

{{ partial "utils/format-date" .Date }}

+ {{- end -}} {{ end }} -{{ end }} +{{ end }} \ No newline at end of file