feat(style): improve style shortcode to support nesting (#263)

This commit is contained in:
Dillon
2020-04-27 01:19:23 +08:00
committed by GitHub
parent f8b84de3f8
commit fc46fba6aa
19 changed files with 90 additions and 63 deletions

View File

@@ -1,16 +1,16 @@
{{- $cdn := .Scratch.Get "cdn" | default dict -}}
{{- $fingerprint := .Scratch.Get "fingerprint" -}}
{{- if not $.Site.Params.app.noFavicon -}}
{{- with $.Site.Params.app.svgFavicon -}}
<link rel="icon" href="/{{ . }}">
{{- if not .Site.Params.app.noFavicon -}}
{{- with .Site.Params.app.svgFavicon -}}
<link rel="icon" href="{{ . }}">
{{- else -}}
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
{{- end -}}
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
{{- with $.Site.Params.app.iconColor -}}
{{- with .Site.Params.app.iconColor -}}
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="{{ . }}">
{{- end -}}
<link rel="manifest" href="/site.webmanifest">

View File

@@ -1,4 +1,8 @@
{{- $content := .Inner | .Page.RenderString -}}
{{- $id := partial "function/id.html" (dict "content" $content) -}}
{{- $tag := .Get 1 | default "div" -}}
{{- printf `<%s id="%s">%s</%s><style>#%s{%s}</style>` $tag $id $content $tag $id ($.Get 0) | safeHTML -}}
{{- $style := .Get 0 | printf "#%s{%s}" $id -}}
{{- $res := resources.FromString "css/shortcode/style.scss" $style -}}
{{- $res = $res | toCSS (dict "targetPath" "css/shortcode/style.css" "outputStyle" "compressed") -}}
{{- printf `<%s id="%s">%s</%s>` $tag $id $content $tag | safeHTML -}}
<style>{{ $res.Content | safeCSS }}</style>