Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to hide posts in blog overview #219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions exampleSite/content/blog/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ title: "Blog"
{{< icon name="rss" attributes="height=14" >}}
{{< /hextra/hero-badge >}}
</div>

Checkout the unlisted post, find it here `/blog/hidden`.
16 changes: 16 additions & 0 deletions exampleSite/content/blog/hidden.md
Original file line number Diff line number Diff line change
@@ -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.
<!--more-->

## Hidden

This post is not shown in the overview page of the blog because is has `hideOnBlog: true` in the front matter.
1 change: 1 addition & 0 deletions exampleSite/content/docs/advanced/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 >}}
56 changes: 56 additions & 0 deletions exampleSite/content/docs/advanced/blog-as-entrypoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
title: Blog as entrypoint
linkTitle: Blog
---

This is a little tutorial how to use the starting page as a blog.

<!--more-->

## 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
---
```
4 changes: 3 additions & 1 deletion layouts/blog/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<h1 class="text-center mt-2 text-4xl font-bold tracking-tight text-slate-900 dark:text-slate-100">{{ .Title }}</h1>
<div class="content">{{ .Content }}</div>
{{ range .Pages.ByDate.Reverse }}
{{- if not .Params.hideOnBlog -}}
<div class="mb-10">
<h3><a style="color: inherit; text-decoration: none;" class="block font-semibold mt-8 text-2xl " href="{{ .RelPermalink }}">{{ .Title }}</a></h3>
{{- if site.Params.blog.list.displayTags -}}
Expand All @@ -25,9 +26,10 @@ <h3><a style="color: inherit; text-decoration: none;" class="block font-semibold
</p>
<p class="opacity-50 text-sm mt-4 leading-7">{{ partial "utils/format-date" .Date }}</p>
</div>
{{- end -}}
{{ end }}
</main>
</article>
<div class="max-xl:hidden h-0 w-64 shrink-0"></div>
</div>
{{ end }}
{{ end }}