From 5d1b38416e8a66b809e65dc84fdb906122009c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Thu, 2 Jun 2022 12:13:16 +0800 Subject: [PATCH] :building_construction: Finish post content template split and the single page coding. --- exampleSite/config.yaml | 4 +- exampleSite/content/post/basic-elements.md | 109 ++++++++++++++++++ exampleSite/content/post/hello-world.md | 13 +-- layouts/_default/baseof.html | 21 ++-- layouts/_default/single.html | 4 + layouts/index.html | 62 +--------- layouts/partials/head/meta.html | 2 +- layouts/partials/post/post_body.html | 11 ++ layouts/partials/post/post_footer.html | 28 +++++ layouts/partials/post/post_header.html | 42 +++++++ .../{ => post}/post_meta/categories.html | 0 .../{ => post}/post_meta/created_date.html | 0 .../{ => post}/post_meta/readtime.html | 0 .../{ => post}/post_meta/update_date.html | 0 .../partials/{ => post}/post_meta/views.html | 0 .../partials/{ => post}/post_meta/words.html | 0 layouts/partials/post_content.html | 10 ++ 17 files changed, 227 insertions(+), 79 deletions(-) create mode 100644 exampleSite/content/post/basic-elements.md create mode 100644 layouts/partials/post/post_body.html create mode 100644 layouts/partials/post/post_footer.html create mode 100644 layouts/partials/post/post_header.html rename layouts/partials/{ => post}/post_meta/categories.html (100%) rename layouts/partials/{ => post}/post_meta/created_date.html (100%) rename layouts/partials/{ => post}/post_meta/readtime.html (100%) rename layouts/partials/{ => post}/post_meta/update_date.html (100%) rename layouts/partials/{ => post}/post_meta/views.html (100%) rename layouts/partials/{ => post}/post_meta/words.html (100%) create mode 100644 layouts/partials/post_content.html diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index ddc40d6..372cf37 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -22,7 +22,7 @@ languages: author: Theme NexT subtitle: Theme for Hugo description: Stay easily & powerful. - keywords: Hugo,Theme,easily,powerful + keywords: Hugo,NexT,Theme,easily,powerful #-------------------------------------- # Menus Settings @@ -103,7 +103,7 @@ params: author: NexT 主题 subtitle: 为 Hugo 打造的主题 description: 保持简单的易用性和强大的功能。 - keywords: Hugo,主题,简单,强大 + keywords: Hugo,NexT,主题,简单,强大 favicon: icon: /imgs/icons/favicon.ico diff --git a/exampleSite/content/post/basic-elements.md b/exampleSite/content/post/basic-elements.md new file mode 100644 index 0000000..d387c45 --- /dev/null +++ b/exampleSite/content/post/basic-elements.md @@ -0,0 +1,109 @@ +--- +title: 'Basic Elements' +description: 'The main purpose of this article is to make sure that all basic HTML Elements are decorated with CSS so as to not miss any possible elements when creating new themes for Hugo.' +keywords: 'Basic,Element' +isCJKLanguage: false + +lastmod: '2022-06-02T11:52:18+08:00' +publishDate: '2022-06-02T11:52:18+08:00' + +categories: + - Example +tags: + - HTML + - Element + +toc: false +draft: true +url: 'basic-elements.html' +--- + +The main purpose of this article is to make sure that all basic HTML Elements are decorated with CSS so as to not miss any possible elements when creating new themes for Hugo. + + + +## Headings + +Let's start with all possible headings. The HTML `

`—`

` elements represent six levels of section headings. `

` is the highest section level and `

` is the lowest. + +# Heading 1 +## Heading 2 +### Heading 3 +#### Heading 4 +##### Heading 5 +###### Heading 6 + +*** + +## Paragraph + +According to the [HTML5 specification](https://www.w3.org/TR/html5/dom.html#elements) by [W3C](https://www.w3.org/), **HTML documents consist of a tree of elements and text**. Each element is denoted in the source by a [start tag](https://www.w3.org/TR/html5/syntax.html#syntax-start-tags), such as ``, and an [end tag](https://www.w3.org/TR/html5/syntax.html#syntax-end-tags), such as ``. (*Certain start tags and end tags can in certain cases be omitted and are implied by other tags.*) + +Elements can have attributes, which control how the elements work. For example, hyperlink are formed using the `a` element and its `href` attribute. + +## List Types + +### Ordered List + +1. First item +2. Second item +3. Third item + +### Unordered List + +* List item +* Another item +* And another item + +### Nested list + + + +### Definition List + +HTML also supports definition lists. + +
+
Blanco tequila
+
The purest form of the blue agave spirit...
+
Reposado tequila
+
Typically aged in wooden barrels for between two and eleven months...
+
+ +## Blockquotes + +The blockquote element represents content that is quoted from another source, optionally with a citation which must be within a `footer` or `cite` element, and optionally with in-line changes such as annotations and abbreviations. + +> Quoted text. +> This line is part of the same quote. +> Also you can *put* **Markdown** into a blockquote. + +Blockquote with a citation. + +
+

My goal wasn't to make a ton of money. It was to build good computers. I only started the company when I realized I could be an engineer forever.

+
Steve Wozniak
+
+ +According to Mozilla's website, Firefox 1.0 was released in 2004 and became a big success. diff --git a/exampleSite/content/post/hello-world.md b/exampleSite/content/post/hello-world.md index cf4aee8..4e4eaff 100644 --- a/exampleSite/content/post/hello-world.md +++ b/exampleSite/content/post/hello-world.md @@ -1,13 +1,10 @@ --- -title: Hello World -description: 'Short description of the article.' -keywords: 'Key words' +title: 'Hello World' isCJKLanguage: false author: 'Author of the article' -lastmod: '2022-05-21T17:06:24+08:00' -publishDate: '2022-05-21T16:06:24+08:00' -weight: 1 +lastmod: '2022-06-02T11:52:03+08:00' +publishDate: '2022-06-02T11:52:03+08:00' categories: - Blog @@ -16,8 +13,8 @@ tags: - Startup toc: false -draft: false -expand: true +draft: true +url: 'hello-world.html' --- The world’s fastest framework for building websites. diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index b2c0679..019df06 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,12 +1,13 @@ -{{- $P := .Site.Params -}} {{- $lang := replaceRE "-([a-z]+)" (upper (substr .Site.Language -3)) .Site.Language -}} {{- .Scratch.Set "lang" $lang -}} {{- $vendors := .Site.Data.resources.vendors -}} -{{- $pluginVen := $P.vendors.plugins -}} +{{- $pluginVen := .Site.Params.vendors.plugins -}} {{- $pluginCDN := index $vendors $pluginVen -}} {{- .Scratch.Set "pluginCDN" $pluginCDN -}} {{ $posts := len (where .Page.Site.RegularPages "Section" "in" .Site.Params.mainSections) }} {{- .Scratch.Set "posts" $posts -}} +{{/* TODO IsHome */}} +{{- .Scratch.Set "IsHome" .IsHome }} @@ -14,11 +15,11 @@ {{ hugo.Generator }} - - - - - + + + + + {{- partial "head.html" . }} {{ .Title | default .Site.Title }} - +
@@ -34,13 +35,13 @@ {{- partial "header.html" . }} - {{- if ne $P.sidebar.display "remove" }} + {{- if ne .Site.Params.sidebar.display "remove" }} {{- partial "sidebar.html" . }} {{- end }}
{{ partial "widgets.html" . }} -
+
{{- block "main" . }}{{- end }}
diff --git a/layouts/_default/single.html b/layouts/_default/single.html index e69de29..4e67b7e 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -0,0 +1,4 @@ +{{- define "main_class" }}page{{- end }} +{{- define "main" }} +{{ partial "post_content.html" . }} +{{- end }} \ No newline at end of file diff --git a/layouts/index.html b/layouts/index.html index 6e1d7de..ba068c2 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -1,64 +1,10 @@ +{{- define "main_class" }}index{{- end }} {{- define "main" }} -{{- $lang := .Scratch.Get "lang" }} +{{/* TODO IsHome */}} +{{- print "Get IsHome value from scratch before paginate: " (.Scratch.Get "IsHome") }} {{ $paginator := .Paginate (where .Site.RegularPages "Section" "in" .Site.Params.mainSections) }} {{- range $paginator.Pages }} -
-
- - - - -
-

- {{/*- with .Sticky }} - {{- if gt . 0 }} - - - - {{- end }} - {{- end */}} - {{/*- if not (eq .Link "") }} - {{ .Title }} - {{- else */}} - - {{/*- end */}} -

- -
- -
- {{- if .Params.Expand }} - {{ .Content }} - {{- else }} - {{ .Summary }} - {{- end }} -
- -
-
+{{ partial "post_content.html" . }} {{- end }} {{- partial "partials/pagination.html" . }} {{- end }} \ No newline at end of file diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html index 2824e3a..01bb521 100644 --- a/layouts/partials/head/meta.html +++ b/layouts/partials/head/meta.html @@ -14,7 +14,7 @@ {{- end }} {{- .Scratch.Set "metaImg" $img }} - + {{- if .Site.Params.darkmode }} {{- else }} diff --git a/layouts/partials/post/post_body.html b/layouts/partials/post/post_body.html new file mode 100644 index 0000000..94d425d --- /dev/null +++ b/layouts/partials/post/post_body.html @@ -0,0 +1,11 @@ +
+ {{- if not .IsHome }} + {{- if .Params.Expand }} + {{ .Content }} + {{- else }} + {{ .Summary }} + {{- end }} + {{- else }} + {{ .Content }} + {{- end }} +
\ No newline at end of file diff --git a/layouts/partials/post/post_footer.html b/layouts/partials/post/post_footer.html new file mode 100644 index 0000000..574fa26 --- /dev/null +++ b/layouts/partials/post/post_footer.html @@ -0,0 +1,28 @@ +{{- if .Scratch.Get "IsHome" }} +{{- if and .Site.Params.readMoreBtn (not .Params.Expand) }} +
+ + {{ T "PostReadMore" }} » + +
+{{- end }} +
+{{- else }} +
+
+ {{- with .NextInSection }} + + {{- end }} +
+
+ {{- with .PrevInSection }} + + {{- end }} +
+
+{{- end }} \ No newline at end of file diff --git a/layouts/partials/post/post_header.html b/layouts/partials/post/post_header.html new file mode 100644 index 0000000..22da400 --- /dev/null +++ b/layouts/partials/post/post_header.html @@ -0,0 +1,42 @@ + + + + +
+

+ {{- if and (isset .Params "sticky") (gt .Params.Sticky 0) }} + + + + {{- end }} + {{- if and (isset .Params "link") (ne .Params.Link "") }} + + {{ .Title }} + + + {{- else }} + + {{- end }} +

+ {{/* TODO IsHome */}} + {{ print "Get IsHome value in pages loop: " ($.Scratch.Get "IsHome") }} + +
\ No newline at end of file diff --git a/layouts/partials/post_meta/categories.html b/layouts/partials/post/post_meta/categories.html similarity index 100% rename from layouts/partials/post_meta/categories.html rename to layouts/partials/post/post_meta/categories.html diff --git a/layouts/partials/post_meta/created_date.html b/layouts/partials/post/post_meta/created_date.html similarity index 100% rename from layouts/partials/post_meta/created_date.html rename to layouts/partials/post/post_meta/created_date.html diff --git a/layouts/partials/post_meta/readtime.html b/layouts/partials/post/post_meta/readtime.html similarity index 100% rename from layouts/partials/post_meta/readtime.html rename to layouts/partials/post/post_meta/readtime.html diff --git a/layouts/partials/post_meta/update_date.html b/layouts/partials/post/post_meta/update_date.html similarity index 100% rename from layouts/partials/post_meta/update_date.html rename to layouts/partials/post/post_meta/update_date.html diff --git a/layouts/partials/post_meta/views.html b/layouts/partials/post/post_meta/views.html similarity index 100% rename from layouts/partials/post_meta/views.html rename to layouts/partials/post/post_meta/views.html diff --git a/layouts/partials/post_meta/words.html b/layouts/partials/post/post_meta/words.html similarity index 100% rename from layouts/partials/post_meta/words.html rename to layouts/partials/post/post_meta/words.html diff --git a/layouts/partials/post_content.html b/layouts/partials/post_content.html new file mode 100644 index 0000000..63f338b --- /dev/null +++ b/layouts/partials/post_content.html @@ -0,0 +1,10 @@ +
+
+ {{ partial "post/post_header.html" . }} + + {{ partial "post/post_body.html" . }} + +
+
\ No newline at end of file