Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/yihui/hugo-xmag.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYihui Xie <xie@yihui.name>2017-07-20 01:11:19 +0300
committerYihui Xie <xie@yihui.name>2017-07-20 01:11:19 +0300
commit412c0591715610b9ce78509a127de31526d83764 (patch)
tree0f8e5c9f3b9824fc53548be6d2d4742248e26666
parentc8d28c33b69730824a1d40bd9a637197613bd033 (diff)
support multiple authors for a single post https://github.com/cosname/cosx.org/issues/637
-rw-r--r--exampleSite/content/about.md7
-rw-r--r--exampleSite/content/post/2017-02-14-hello-markdown.md4
-rw-r--r--exampleSite/data/authors.yaml1
-rw-r--r--layouts/_default/list.html2
-rw-r--r--layouts/_default/single.html4
-rw-r--r--layouts/partials/author.html19
-rw-r--r--layouts/partials/author_names.html1
7 files changed, 31 insertions, 7 deletions
diff --git a/exampleSite/content/about.md b/exampleSite/content/about.md
index d8e7583..5ef2b71 100644
--- a/exampleSite/content/about.md
+++ b/exampleSite/content/about.md
@@ -19,6 +19,8 @@ This theme includes a few cool features:
- Author info and site info at the bottom of an article
+- Multiple authors of a single page
+
- MathJax for LaTeX math expressions
It also supports features that are probably not even worth mentioning:
@@ -89,6 +91,7 @@ There are a few phrases that you can "translate" (I didn't use Hugo's multi-lang
```toml
[params.text]
about_author = "About the Author"
+ author_delimiter = ", "
back = "Back to Home"
edit = "Edit this page"
tags = "Tags: "
@@ -109,7 +112,7 @@ To add a table of contents to an article, you can add `toc: true` to the YAML me
# Custom layouts
-Besides the custom layout^[If this is the first time you have heard about "customizing layouts", please read the Hugo documentation first: https://gohugo.io/themes/customizing/.] files `head_custom.html` and `foot_custom.html` supported in **XMin** (see [documentation](https://xmin.yihui.name/about/)), this theme added a few more layout files `banner.html`, `comments.html` and `info.html` under `layouts/partials/`. The first can be used to customize the banner. The second can be used to add a comment section, e.g., if you want to use Hugo's default Disqus template, just add this to `comments.html`:
+Besides the custom layout^[If this is the first time you have heard about "customizing layouts", please read the Hugo documentation first: https://gohugo.io/themes/customizing/.] files `head_custom.html` and `foot_custom.html` supported in **XMin** (see [documentation](https://xmin.yihui.name/about/)), this theme added a few more layout files such as `banner.html`, `comments.html` and `info.html` under `layouts/partials/`. The first can be used to customize the banner. The second can be used to add a comment section, e.g., if you want to use Hugo's default Disqus template, just add this to `comments.html`:
```
{{ template "_internal/disqus.html" . }}
@@ -117,6 +120,8 @@ Besides the custom layout^[If this is the first time you have heard about "custo
You can also append arbitrary text to each article through `info.html`. For example, you may declare copyrights or briefly introduce your site.
+There are other partial templates in this theme and I encourage you to read the source code to figure out what they do.
+
# Final words
I feel the world has become so noisy that I'm often at a loss when looking at a web page, because there are so many things to distract me. I was heavily influenced by the book [_Amusing Ourselves to Death_](https://en.wikipedia.org/wiki/Amusing_Ourselves_to_Death) after I read it in early 2017. From then on, I was hoping to design a theme for a website that gives articles the top priority. Everything else must give way to articles. That is why the navigation menu is at the bottom instead of in the conventional position (top or sidebar). There isn't much to do other than reading an article when you open a page. By the way, this is a pure plain-text theme. You can certainly add images if you want, but this theme itself contains zero binary files. Out of my [OCD](https://en.wikipedia.org/wiki/Obsessive%E2%80%93compulsive_disorder), I was just trying to push the limits of web design without using any images or JavaScript libraries (I'm a totally amateur).^[I used MathJax and highlight.js anyway in this theme because they are helpful.]
diff --git a/exampleSite/content/post/2017-02-14-hello-markdown.md b/exampleSite/content/post/2017-02-14-hello-markdown.md
index f87f71c..f694f16 100644
--- a/exampleSite/content/post/2017-02-14-hello-markdown.md
+++ b/exampleSite/content/post/2017-02-14-hello-markdown.md
@@ -1,6 +1,8 @@
---
title: A Plain Markdown Post
-author: Yihui Xie
+author:
+ - Yihui Xie
+ - Frida Gomam
date: '2017-02-14'
categories:
- Example
diff --git a/exampleSite/data/authors.yaml b/exampleSite/data/authors.yaml
index e00b1bf..800a25a 100644
--- a/exampleSite/data/authors.yaml
+++ b/exampleSite/data/authors.yaml
@@ -1 +1,2 @@
"Yihui Xie": "Yihui Xie is currently a softwaren engineer at [RStudio](https://www.rstudio.com). You can find more information about him at https://yihui.name."
+"Frida Gomam": "Frida Gomam is a joke."
diff --git a/layouts/_default/list.html b/layouts/_default/list.html
index 4016581..752be70 100644
--- a/layouts/_default/list.html
+++ b/layouts/_default/list.html
@@ -16,7 +16,7 @@
</div>
<h1><a href="{{ .URL }}">{{ .Title }}</a></h1>
<div class="date-author">
- {{ with .Params.author }}<span class="author">{{ . }}</span> / {{ end }}
+ {{ if .Params.author }}<span class="author">{{ partial "author_names.html" . }}</span> / {{ end }}
<span class="date">{{ .Date.Format "2006-01-02" }}</span>
</div>
<div class="summary">
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 62f1c83..173ec3b 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -11,8 +11,8 @@
<h1><span class="title">{{ .Title }}</span></h1>
- {{ with .Params.author }}
- <h3 class="author">{{ . }}</h3>
+ {{ if .Params.author }}
+ <h3 class="author">{{ partial "author_names.html" . }}</h3>
{{ end }}
{{ with .Params.tags }}
diff --git a/layouts/partials/author.html b/layouts/partials/author.html
index c5ed53d..c4977ab 100644
--- a/layouts/partials/author.html
+++ b/layouts/partials/author.html
@@ -1,10 +1,25 @@
{{ with .Params.author }}
+{{ if eq (substr (jsonify .) 0 1) "["}}
+{{ $.Scratch.Set "page_author" .}}
+{{ else }}
+{{ $.Scratch.Set "page_author" (slice .) }}
+{{ end }}
+
+{{ $.Scratch.Set "author_info" slice }}
{{ if $.Site.Data.authors }}
+{{ range $.Scratch.Get "page_author" }}
{{ with (index $.Site.Data.authors .) }}
+{{ $.Scratch.Add "author_info" . }}
+{{ end }}
+{{ end }}
+{{ end }}
+{{ if $.Scratch.Get "author_info" }}
<section class="article-meta article-footer">
<h3>{{ default "About the Author" $.Site.Params.text.about_author }}</h3>
- <p>{{ . | markdownify }}</p>
+ {{ range $.Scratch.Get "author_info" }}
+ <p>{{ . | markdownify }}</p>
+ {{ end }}
</section>
{{ end }}
-{{ end }}
+
{{ end }}
diff --git a/layouts/partials/author_names.html b/layouts/partials/author_names.html
new file mode 100644
index 0000000..bbbc978
--- /dev/null
+++ b/layouts/partials/author_names.html
@@ -0,0 +1 @@
+{{ replace ((jsonify .Params.author) | replaceRE "[\\[\"\\]]" "") "," (default ", " $.Site.Params.text.author_delimiter) | safeHTML }}