Skip to content

Commit

Permalink
add news
Browse files Browse the repository at this point in the history
- add news page
- add news to home
  • Loading branch information
yishanhe committed Sep 4, 2021
1 parent a27a143 commit 20017d4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
5 changes: 5 additions & 0 deletions exampleSite/archetypes/news.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---
5 changes: 5 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ weight = 4
show_updated = true # default
showReadTime = true # default

[params.news]
enabled = true # default
newsOnHomePage = 5


[params.comments]
enabled = true # default
engine = "cactus_comments" # only disqus, utterances, and cactus_comments is supported
Expand Down
5 changes: 5 additions & 0 deletions exampleSite/content/news/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: News
date: 2016-08-24 17:51:42
type: news
---
30 changes: 30 additions & 0 deletions exampleSite/data/news.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"list": [
{
"date": "Apr 2021",
"desc": "news dummy content 1",
"url": "https://www.google.com"
},
{
"date": "Jan 2020",
"desc": "news dummy content 2"
},
{
"date": "Dec 2019",
"desc": "news dummy content 3"
},
{
"date": "Apr 2018",
"desc": "news dummy content 4",
"url": "https://www.google.com"
},
{
"date": "Jan 2017",
"desc": "news dummy content 5"
},
{
"date": "Dec 2016",
"desc": "news dummy content 6"
}
]
}
23 changes: 23 additions & 0 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,27 @@
</ul>
</section>
{{ end }}


{{ $showNews := false }}
{{ if (isset .Site.Params "news") }}
{{ $showNews = .Site.Params.News.Enabled | default false }}
{{ end }}
{{ if $showNews }}
<section id="news">
<span class="h1"><a href={{ "news" | absURL }}>News</a></span>
<ul class="news-list">
{{ $newsLimit := .Site.Params.News.NewsOnHomePage | default 5 }}
{{ range first $newsLimit .Site.Data.news.list }}
<li class="news-item">
{{ .date }}:
{{ if .url }}<a href="{{ .url }}">{{ end }}
{{ .desc | markdownify }}
{{ if .url }}</a>{{ end }}
</li>
{{ end }}
</ul>
</section>
{{ end }}

{{ end }}
33 changes: 33 additions & 0 deletions layouts/news/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{ define "main" }}
<article class="post" itemscope itemtype="http://schema.org/BlogPosting">
<!-- TODO: gallery -->
<div class="content" itemprop="articleBody">

{{ $showNews := false }}
{{ if (isset .Site.Params "news") }}
{{ $showNews = .Site.Params.News.Enabled | default false }}
{{ end }}
{{ if $showNews }}
<section id="news">
<span class="h1"><a href={{ "news" | absURL }}>News</a></span>
<ul class="post-list">
{{ range .Site.Data.news.list }}
<li class="post-item">
<div class="meta">
<time>{{ .date }}</time>
</div>
<span>
{{ if .url }}<a href="{{ .url }}">{{ end }}
{{ .desc | markdownify }}
{{ if .url }}</a>{{ end }}
</span>

</li>
{{ end }}
</ul>
</section>
{{ end }}

</div>
</article>
{{ end }}

1 comment on commit 20017d4

@RobbiNespu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw on monkeyWzr#107 and this is great features

Please sign in to comment.