Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
fix(check): fix some html check bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq committed Feb 18, 2020
1 parent d8681cd commit 4b3addf
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 67 deletions.
9 changes: 4 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ jobs:
theme-path:
type: string
docker:
- image: cibuilds/hugo:0.64
- image: cibuilds/hugo:0.62
working_directory: ~/LoveIt
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init
- run:
command: |
cd << parameters.example-site-path >>
pwd
HUGO_ENV=production hugo --themesDir << parameters.theme-path >> -v --minify --gc
htmlproofer public --allow-hash-href --empty-alt-ignore --disable-external
cd << parameters.example-site-path >> && pwd
HUGO_ENV=production hugo --themesDir << parameters.theme-path >> -v --gc
htmlproofer public --check-html --allow-hash-href --empty-alt-ignore --disable-external
workflows:
build-check-exampleSite:
jobs:
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/posts/markdown-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ in-line changes such as annotations and abbreviations.
### Blockquote with attribution

> Don't communicate by sharing memory, share memory by communicating.</p>
> Don't communicate by sharing memory, share memory by communicating.
> — <cite>Rob Pike[^1]</cite>
[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015.
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/zh/content/posts/Basic-Markdown-Preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Markdown 开始被应用于网络以外的领域,包括作者书籍、文章

我们可以把一个文档看成一系列的块,如段落、引用、列表、标题和代码块。

有些块(如引号和列表)可以包含其它的块,即 **容器块**
有些块(如引号和列表)可以包含其它的块,即 **容器块**
其他的块(如标题和段落)则包含内联元素(如文本、链接、强调、图像、内联代码等),即 **叶子块**

块的符号总是优先于内联元素的符号。例如:
Expand Down
1 change: 0 additions & 1 deletion exampleSite/zh/content/posts/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ Here is a story about love...
{{< /typeit >}}
{{< typeit group="test" code="java" >}}
u.accepted(); // [2018/01/05](/since/) special
int a = 1;
{{< /typeit >}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{- partial "function/image.html" (dict "src" .Destination "alt" .Text "title" .Title ) -}}
{{- with .Title | default .Text -}}
<figcaption class="image-caption">
{{- . -}}
{{- . | safeHTML -}}
</figcaption>
{{- end -}}
</figure>
14 changes: 5 additions & 9 deletions layouts/index.atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link href="{{ .Permalink }}"/>
{{- if not .Date.IsZero -}}
<updated>
{{- .Date.Format "02-01-2006T15:04:05-07:00" | safeHTML -}}
{{- .Date.Format "02-01-2006T15:04:05-07:00" -}}
</updated>
{{- end -}}
<id>
Expand All @@ -21,9 +21,7 @@
<generator>Hugo -- gohugo.io</generator>
{{- range first 15 (where .Data.Pages "Type" "in" .Site.Params.mainSections) -}}
<entry>
<title type="html">
{{- printf "<![CDATA[%s]]>" .Title | safeHTML -}}
</title>
<title type="html"><![CDATA[{{ .Title -}}]]></title>
<link href="{{ .Permalink }}"/>
<id>
{{- .Permalink -}}
Expand All @@ -36,14 +34,12 @@
</author>
{{- end -}}
<published>
{{- .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML -}}
{{- .Date.Format "2006-01-02T15:04:05-07:00" -}}
</published>
<updated>
{{- .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML -}}
{{- .Lastmod.Format "2006-01-02T15:04:05-07:00" -}}
</updated>
<content type="html">
{{- printf "<![CDATA[%s]]>" .Content | safeHTML -}}
</content>
<content type="html"><![CDATA[{{- .Content -}}]]></content>
</entry>
{{- end -}}
</feed>
6 changes: 3 additions & 3 deletions layouts/partials/head/seo.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
"wordcount": {{ .WordCount }},
"url": "{{ .Permalink }}",
{{- if not .PublishDate.IsZero -}}
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}",
{{- else if not .Date.IsZero -}}
"datePublished": "{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
"datePublished": "{{ .Date.Format "2006-01-02T15:04:05-07:00" }}",
{{- end -}}
{{- with .Lastmod -}}
"dateModified": "{{ .Format "2006-01-02T15:04:05-07:00" | safeHTML }}",
"dateModified": "{{ .Format "2006-01-02T15:04:05-07:00" }}",
{{- end -}}
{{- with .Site.Copyright -}}
"license": "{{ . }}",
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{{- $currentPage := . -}}
{{- range .Site.Menus.main -}}
<a class="menu-item" href="{{ .URL | absLangURL }}" title="{{ .Title }}">
{{- .Name | safeHTML -}}
{{- .Pre | safeHTML }}{{ .Name -}}
</a>
{{- end -}}
<a href="javascript:void(0);" class="theme-switch" title="{{ T "switchTheme" }}">
Expand Down
8 changes: 6 additions & 2 deletions layouts/partials/home/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ <h2 class="home-description">
{{- if $.Site.Params.home.profile.typeit -}}
{{- $id := md5 . | printf "tp-%s" -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- . | safeHTML -}}
{{- /* FIXME: https://github.com/gohugoio/hugo/issues/6882 */ -}}
{{- /* . | $.RenderString | safeHTML */ -}}
{{- . | markdownify | safeHTML -}}
</div>
<div id={{ $id }} class="typeit"></div>
{{- $.Scratch.SetInMap "typeitMap" $id (slice $id) -}}
{{- else -}}
{{- . | safeHTML -}}
{{- /* FIXME: https://github.com/gohugoio/hugo/issues/6882 */ -}}
{{- /* . | $.RenderString | safeHTML */ -}}
{{- . | markdownify | safeHTML -}}
{{- end -}}
</h2>
{{- end -}}
Expand Down
8 changes: 4 additions & 4 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ <h1 class="single-title animated flipInX">{{ .Title }}</h1>

{{- /* TOC */ -}}
{{- if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) -}}
<div class="post-toc" id="post-toc">
<aside class="post-toc" id="post-toc">
<h2 class="post-toc-title">{{ T "toc" }}</h2>
{{- $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default true }}
<div class="post-toc-content{{ if not (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false)) }} always-active{{ end }}">
{{- .TableOfContents -}}
</div>
</div>
<div class="post-toc-mobile" id="post-toc-mobile">
</aside>
<aside class="post-toc-mobile" id="post-toc-mobile">
<details>
<summary>
<div class="post-toc-title">
Expand All @@ -68,7 +68,7 @@ <h2 class="post-toc-title">{{ T "toc" }}</h2>
{{- $toc | safeHTML -}}
</div>
</details>
</div>
</aside>
{{- end -}}

{{- /* Content */ -}}
Expand Down
4 changes: 2 additions & 2 deletions layouts/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{{- end -}}
{{- if not .Date.IsZero -}}
<lastBuildDate>
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML -}}
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</lastBuildDate>
{{- end -}}
<atom:link href="{{.Permalink}}" rel="self" type="application/rss+xml" />
Expand All @@ -43,7 +43,7 @@
{{- .Permalink -}}
</link>
<pubDate>
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML -}}
{{- .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" -}}
</pubDate>
{{- with .Site.Author.email -}}
<author>
Expand Down
11 changes: 6 additions & 5 deletions layouts/shortcodes/admonition.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- $_hugo_config := `{ "version": 1 }` -}}
{{- $inner := .Inner | .Page.RenderString -}}

{{- $iconMap := dict "note" "fas fa-pencil-alt" -}}
{{- $iconMap = dict "abstract" "fas fa-list-ul" | merge $iconMap -}}
{{- $iconMap = dict "info" "fas fa-info-circle" | merge $iconMap -}}
Expand All @@ -22,14 +23,14 @@
<i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}<i class="details {{ $iconDetails }}"></i>
</summary>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</details>
{{- else -}}
<div class="admonition {{ $type }}">
{{- with .Get "title" -}}
<p class="admonition-title"><i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}</p>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</div>
{{- end -}}
{{- else -}}
Expand All @@ -41,14 +42,14 @@
<i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}<i class="details {{ $iconDetails }}"></i>
</summary>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</details>
{{- else -}}
<div class="admonition {{ $type }}">
{{- with .Get 1 -}}
<p class="admonition-title"><i class="icon {{ index $iconMap $type | default (index $iconMap "note") }}"></i>{{ . }}</p>
{{- end -}}
{{- .Inner -}}
{{- $inner -}}
</div>
{{- end -}}
{{- end -}}
5 changes: 2 additions & 3 deletions layouts/shortcodes/align.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{ $_hugo_config := `{ "version": 1 }` -}}
<!-- [left, center, right] -->
{{- /* [left, center, right] */ -}}
<div class={{ .Get 0 | printf "align-%s" }}>
{{- .Inner -}}
{{- .Inner | .Page.RenderString -}}
</div>
5 changes: 2 additions & 3 deletions layouts/shortcodes/float.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{ $_hugo_config := `{ "version": 1 }` -}}
<!-- [left, right] -->
{{- /* [left, right] */ -}}
<div class={{ .Get 0 | printf "float-%s" }}>
{{- .Inner -}}
{{- .Inner | .Page.RenderString -}}
</div>
2 changes: 1 addition & 1 deletion layouts/shortcodes/mermaid.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- shuffle md5 as id -->
{{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 .Inner) "" | shuffle) "" | printf "mermaid-%s" -}}
<div class="mermaid" id="{{ $id }}"></div>
{{- .Page.Scratch.SetInMap "mermaidMap" $id (trim .Inner "\n") -}}
20 changes: 10 additions & 10 deletions layouts/shortcodes/typeit.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<!-- only the trailing newline is retained -->
{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner -}}
<!-- shuffle md5 as id -->
{{- /* only the trailing newline is retained */ -}}
{{- $content := replaceRE `(?s)^\n*(.*?)\n*$` "$1\n" .Inner | .Page.RenderString -}}
{{- /* shuffle md5 as id */ -}}
{{- $id := delimit (split (md5 $content) "" | shuffle) "" | printf "typeit-%s" -}}

<div class={{ .Get "class" | default "typeit" }}>
<!-- raw html content -->
{{- /* raw html content */ -}}
{{- if .Get "raw" -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>
<div id={{ $id }}></div>
{{- else if .Get "code" -}}
<!-- highlight code content without line number -->
{{- /* highlight code content without line number */ -}}
{{- $content = highlight $content (.Get "code") "linenos=false" -}}
<!-- delete outer label -->
{{- /* delete outer label */ -}}
{{- $content = replaceRE `<div class="highlight"><pre class="chroma"><code[^<>]*>(?s)(.*)</code></pre></div>` "$1" $content -}}
<!-- parsing markdown links -->
{{- /* parsing markdown links */ -}}
{{- $content = replaceRE `(<span[^<>]*>)([^<>]*)\[([^<>]+)\]\(([^<>]+)\)([^<>]*)(</span>)` "$1$2$6<a href=$4>$3</a>$1$5$6" $content -}}
<!-- replace " " to "&nbsp;" and replace "\n" to "<br />" -->
{{- /* replace " " to "&nbsp;" and replace "\n" to "<br />" */ -}}
{{- $content = replaceRE ` ` "&nbsp;" $content | replaceRE `(<\w+)&nbsp;` "$1 " | replaceRE `\n` "<br />" -}}
<!-- fix "<br />" location error which is a bug of Typeit HTML parser -->
{{- /* fix "<br />" location error which is a bug of Typeit HTML parser */ -}}
{{- $content = replaceRE `<br /></span>` "</span><br />" $content -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>
<div class="highlight" id={{ $id }}></div>
{{- else -}}
{{- $tag := .Get "tag" | default "p" -}}
{{- $content = $content | markdownify | chomp -}}
{{- $content = $content | chomp -}}
<div id={{ printf "r%s" $id }} hidden=true>
{{- $content | safeHTML -}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion layouts/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</loc>
{{- if not .Lastmod.IsZero -}}
<lastmod>
{{- safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) -}}
{{- .Lastmod.Format "2006-01-02T15:04:05-07:00" -}}
</lastmod>
{{- end -}}
{{- with .Sitemap.ChangeFreq -}}
Expand Down
12 changes: 1 addition & 11 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@
this.util.forEach(toc.querySelectorAll('a:first-child'), (link) => {
link.classList.add('toc-link');
});

// when headings do not start with `h1`
const oldTocList = toc.children[0];
let newTocList = oldTocList;
let temp;
while (newTocList.children.length === 1
&& (temp = newTocList.children[0].children[0]).tagName === 'UL') {
newTocList = temp;
}
if (newTocList !== oldTocList) toc.replaceChild(newTocList, oldTocList);
}

_initTocState(tocContainer) {
Expand Down Expand Up @@ -157,7 +147,7 @@
initToc() {
const tocContainer = document.getElementById('post-toc');
if (tocContainer !== null) {
const toc = document.getElementById('TableOfContents');
const toc = tocContainer.getElementById('TableOfContents');
if (toc === null) {
tocContainer.parentElement.removeChild(tocContainer);
} else {
Expand Down
Loading

0 comments on commit 4b3addf

Please sign in to comment.