feat: smarter typeit shortcode

This commit is contained in:
Dillon ZENG
2019-08-11 03:26:03 +08:00
parent c16db324fa
commit a6bf8d8eae
10 changed files with 253 additions and 166 deletions

View File

@@ -1,75 +1,58 @@
{{ $cdn_url := .Scratch.Get "cdn_url" }}
<div class="post-warp">
<div class="intro">
{{ $avatar := "" }}
{{ if or .Params.gravatar.Email (and .Site.Params.gravatar.Email (ne .Params.gravatar.Email false)) }}
{{ $avatar = (printf "https://www.gravatar.com/avatar/%s?s=240&d=mp" (md5 .Site.Params.gravatar.email)) }}
{{ else if .Site.Params.avatar }}
{{ $avatar = (printf "%s%s" $cdn_url .) }}
{{ end }}
{{ if $avatar }}
<div class="avatar">
<a href="/posts/"> <img src={{ $avatar }} alt="avatar"></a>
{{ partial "intro.html" . }}
{{ range (.Paginate (where .Pages "Type" "posts")).Pages }}
<article class="post" itemscope itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="{{ .Permalink }}">{{ .Title }}</a>
</h1>
</header>
<div class="post-content">
<!--featured_image-->
{{ with .Params.featured_image }}
{{ $img := . }}
<p>
<img itemprop="image" src="{{ printf "%s%s" $cdn_url $img }}" class="featured_image">
</p>
{{ end }}
<!-- end featured_image-->
{{ .Summary }}
</div>
{{ end }}
{{ with .Site.Params.subtitle }}
<h2 class="description">
<div id="subtitle"></div>
</h2>
<script>
var typeitMap = window.typeitMap || {};
typeitMap["#subtitle"] = "{{ . }}";
</script>
{{ end }}
</div>
{{ range (.Paginate .Pages).Pages }}
<article class="post" itemscope itemscope="" itemtype="http://schema.org/Article">
<header class="post-header">
<h1 class="post-title" itemprop="name headline"><a href="{{ .Permalink }}">{{ .Title }}</a></h1>
</header>
<div class="post-content">
<!--featured_image-->
{{ with .Params.featured_image }}
{{- $img := . -}}
<p><img src="{{ printf "%s%s" $cdn_url $img }}" class="featured_image"></p>
{{ end }}
<!-- end featured_image-->
{{ .Summary }}
</div>
<div class="post-footer">
<div class="post-meta">
<span class="post-time">
<time datetime={{.Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }}
itemprop="datePublished">{{ .Date.Format (.Site.Params.dateFormatToUse | default "2 January 2006") }}</time>
</span>
in
{{ with .Params.categories -}}
<i class="iconfont icon-folder"></i>
<span class="post-category">
{{ range . }}
{{- $name := . -}}
{{- with $.Site.GetPage "taxonomy" (printf "categories/%s" $name) | default ($.Site.GetPage "taxonomy" (printf "categories/%s" ($name | urlize))) -}}
<a href="{{ .Permalink }}"> {{ $name }} </a>
{{ end -}}
<div class="post-footer">
<div class="post-meta">
<span class="post-time">
<time datetime={{.Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} itemprop="datePublished">
{{ .Date.Format (.Site.Params.dateFormatToUse | default "2 January 2006") }}
</time>
</span>
in
{{ with .Params.categories }}
<i class="iconfont icon-folder"></i>
<span class="post-category">
{{ range . }}
{{ $name := . }}
{{ with $.Site.GetPage "taxonomy" (printf "categories/%s" $name) | default ($.Site.GetPage "taxonomy" (printf "categories/%s" ($name | urlize))) }}
<a href="{{ .Permalink }}">{{ $name }}</a>
{{ end }}
{{ end }}
</span>
{{ end }}
</span>
{{- end }}
</div>
{{ with .Params.tags }}
<div class="post-tags">
{{ range . }}
<span class="tag"><a href="{{ "tags/" | absURL }}{{ . | urlize }}/">
#{{.}}</a></span>
</div>
{{ with .Params.tags }}
<div class="post-tags">
{{ range . }}
<span class="tag">
<a href="{{ "tags/" | absURL }}{{ . | urlize }}/">#{{ . }}</a>
</span>
{{ end }}
</div>
{{ end }}
</div>
{{ end }}
</div>
</article>
</article>
{{ end }}
{{ partial "paginator.html" . }}

View File

@@ -1,29 +1 @@
{{ $cdn_url := .Scratch.Get "cdn_url" }}
<div class="intro">
{{ $avatar := "" }}
{{ if or .Params.gravatar.Email (and .Site.Params.gravatar.Email (ne .Params.gravatar.Email false)) }}
{{ $avatar = (printf "https://www.gravatar.com/avatar/%s?s=240&d=mp" (md5 .Site.Params.gravatar.email)) }}
{{ else if .Site.Params.avatar }}
{{ $avatar = (printf "%s%s" $cdn_url .) }}
{{ end }}
{{ if $avatar }}
<div class="avatar">
<a href="/posts/"> <img src={{ $avatar }} alt="avatar"></a>
</div>
{{ end }}
{{ with .Site.Params.subtitle }}
<h2 class="description">
<div id="subtitle"></div>
</h2>
<script>
var typeitMap = window.typeitMap || {};
typeitMap["#subtitle"] = "{{ . }}";
</script>
{{ end }}
<div class="social-links">
{{ partial "social.html" . }}
</div>
</div>
{{ partial "intro.html" . }}

View File

@@ -0,0 +1,33 @@
{{ $cdn_url := .Scratch.Get "cdn_url" }}
<div class="intro">
{{ $avatar := "" }}
{{ if or .Params.gravatar.Email (and .Site.Params.gravatar.Email (ne .Params.gravatar.Email false)) }}
{{ $avatar = (printf "https://www.gravatar.com/avatar/%s?s=240&d=mp" (md5 .Site.Params.gravatar.email)) }}
{{ else if .Site.Params.avatar }}
{{ $avatar = (printf "%s%s" $cdn_url .Site.Params.avatar) }}
{{ end }}
{{ if $avatar }}
<div class="avatar">
<a href="/posts/">
<img src={{ $avatar }} alt="avatar">
</a>
</div>
{{ end }}
{{ with .Site.Params.subtitle }}
<h2 class="description">
{{ $id := md5 . | printf "tp-%s" }}
<div id={{ printf "r%s" $id }} hidden=true>{{ . | safeHTML }}</div>
<div id={{ $id }} class="typeit"></div>
<script>
var typeitMap = window.typeitMap || {};
typeitMap[{{ $id }}] = true;
</script>
</h2>
{{ end }}
<div class="social-links">
{{ partial "social.html" . }}
</div>
</div>

View File

@@ -1,5 +1,5 @@
{{ $cdn_url := .Scratch.Get "cdn_url" }}
{{ $postHasImages := .Scratch.Get "postHasImages"}}
{{ $postHasImages := .Scratch.Get "postHasImages" }}
{{ $scripts := resources.Get "/js/main.js" | slice }}
{{ $dynamicToTop := resources.Get "/js/dynamicToTop.min.js" }}
@@ -9,10 +9,6 @@
{{ $jquery := `
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
` }}
<!-- JavaScript code prettifier https://github.com/google/code-prettify -->
{{ $prettify := `
<script src="https://cdn.jsdelivr.net/npm/code-prettify@0.1.0/src/prettify.js" integrity="sha256-w3n8zE0N1lx/nrrWA16Dk7KnySbJF7cPs5E2CByeB7A=" crossorigin="anonymous"></script>
` }}
<!-- lightGallery https://github.com/sachinchoolur/lightGallery -->
{{ $lightGallery := `
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.12/dist/css/lightgallery.min.css" integrity="sha256-8rfHbJr+ju3Oc099jFJMR1xAPu8CTPHU8uP5J3X/VAY=" crossorigin="anonymous">
@@ -49,9 +45,6 @@
{{ $typeit | safeHTML }}
{{ if .IsPage }}
{{ if .Params.Code }}
{{ $prettify | safeHTML }}
{{ end }}
{{ if .Params.Music }}
{{ $metingjs | safeHTML }}
{{ end }}
@@ -76,5 +69,4 @@
{{ end }}
<script src="{{ printf "%s%s" $cdn_url $scripts.RelPermalink }}" async=""></script>
{{ template "_internal/google_analytics_async.html" . }}