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

@@ -15,6 +15,7 @@
padding: 30% 0 0; padding: 30% 0 0;
position: relative; position: relative;
margin: 0.6rem auto; margin: 0.6rem auto;
@include transition(transform 0.4s ease);
img { img {
position: absolute; position: absolute;
@@ -24,6 +25,10 @@
top: 0; top: 0;
object-fit: cover; object-fit: cover;
} }
&:hover {
@include transform(scale(1.01));
}
} }
.single-title { .single-title {

View File

@@ -98,12 +98,12 @@ enableEmoji = true
# App icon config # App icon config
[languages.en.params.app] [languages.en.params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher # optional site title override for the app when added to an iOS home screen or Android launcher
title = "LoveIt App" title = "LoveIt"
# whether to omit favicon resource links # whether to omit favicon resource links
noFavicon = true noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files # modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg' svgFavicon = ""
# Android browser color theming # Android browser theme color
themeColor = "#ffffff" themeColor = "#ffffff"
# Safari mask icon color # Safari mask icon color
iconColor = "#5bbad5" iconColor = "#5bbad5"
@@ -284,19 +284,19 @@ enableEmoji = true
description = "关于 LoveIt 主题" description = "关于 LoveIt 主题"
# 网站关键词 # 网站关键词
keywords = ["Theme", "Hugo"] keywords = ["Theme", "Hugo"]
# App icon config # 应用图标配置
[languages.zh-cn.params.app] [languages.zh-cn.params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher # 当添加到 iOS 主屏幕或者 Android 启动器时的标题, 覆盖默认标题
title = "LoveIt App" title = "LoveIt"
# whether to omit favicon resource links # 是否隐藏网站图标资源链接
noFavicon = true noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files # 更现代的 SVG 网站图标, 可替代旧的 .png .ico 文件
svgFavicon = 'favicon.svg' svgFavicon = ""
# Android browser color theming # Android 浏览器主题色
themeColor = "#ffffff" themeColor = "#ffffff"
# Safari mask icon color # Safari 图标颜色
iconColor = "#5bbad5" iconColor = "#5bbad5"
# Windows v8-10 tile color # Windows v8-10 磁贴颜色
tileColor = "#da532c" tileColor = "#da532c"
# 搜索配置 # 搜索配置
[languages.zh-cn.params.search] [languages.zh-cn.params.search]
@@ -472,12 +472,12 @@ enableEmoji = true
# App icon config # App icon config
[languages.fr.params.app] [languages.fr.params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher # optional site title override for the app when added to an iOS home screen or Android launcher
title = "LoveIt App" title = "LoveIt"
# whether to omit favicon resource links # whether to omit favicon resource links
noFavicon = true noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files # modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg' svgFavicon = ""
# Android browser color theming # Android browser theme color
themeColor = "#ffffff" themeColor = "#ffffff"
# Safari mask icon color # Safari mask icon color
iconColor = "#5bbad5" iconColor = "#5bbad5"

View File

@@ -9,11 +9,13 @@ math:
enable: true enable: true
--- ---
{{< style "img { height: 1.25rem; }" >}}
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/releases) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/releases)
[![Hugo](https://img.shields.io/badge/Hugo-%5E0.62.0-ff4088?style=flat-square&logo=hugo)](https://gohugo.io/) [![Hugo](https://img.shields.io/badge/Hugo-%5E0.62.0-ff4088?style=flat-square&logo=hugo)](https://gohugo.io/)
[![License](https://img.shields.io/github/license/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/blob/master/LICENSE) [![License](https://img.shields.io/github/license/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt) [![GitHub stars](https://img.shields.io/github/stars/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt)
[![GitHub forks](https://img.shields.io/github/forks/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt/fork) [![GitHub forks](https://img.shields.io/github/forks/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt/fork)
{{< /style >}}
[:(far fa-kiss-wink-heart fa-fw): LoveIt](https://github.com/dillonzq/LoveIt) is a **clean**, **elegant** but **advanced** blog theme for [Hugo](https://gohugo.io/) developed by [Dillon](https://dillonzq.com). [:(far fa-kiss-wink-heart fa-fw): LoveIt](https://github.com/dillonzq/LoveIt) is a **clean**, **elegant** but **advanced** blog theme for [Hugo](https://gohugo.io/) developed by [Dillon](https://dillonzq.com).

View File

@@ -9,11 +9,13 @@ math:
enable: true enable: true
--- ---
{{< style "img { height: 1.25rem; }" >}}
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/releases) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/releases)
[![Hugo](https://img.shields.io/badge/Hugo-%5E0.62.0-ff4088?style=flat-square&logo=hugo)](https://gohugo.io/) [![Hugo](https://img.shields.io/badge/Hugo-%5E0.62.0-ff4088?style=flat-square&logo=hugo)](https://gohugo.io/)
[![License](https://img.shields.io/github/license/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/blob/master/LICENSE) [![License](https://img.shields.io/github/license/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt) [![GitHub stars](https://img.shields.io/github/stars/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt)
[![GitHub forks](https://img.shields.io/github/forks/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt/fork) [![GitHub forks](https://img.shields.io/github/forks/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt/fork)
{{< /style >}}
{{< admonition warning >}} {{< admonition warning >}}
Sorry, this article has not been completely translated into **French**. Sorry, this article has not been completely translated into **French**.

View File

@@ -9,11 +9,13 @@ math:
enable: true enable: true
--- ---
{{< style "img { height: 1.25rem; }" >}}
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/releases) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/releases)
[![Hugo](https://img.shields.io/badge/Hugo-%5E0.62.0-ff4088?style=flat-square&logo=hugo)](https://gohugo.io/) [![Hugo](https://img.shields.io/badge/Hugo-%5E0.62.0-ff4088?style=flat-square&logo=hugo)](https://gohugo.io/)
[![License](https://img.shields.io/github/license/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/blob/master/LICENSE) [![License](https://img.shields.io/github/license/dillonzq/LoveIt?style=flat-square)](https://github.com/dillonzq/LoveIt/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt) [![GitHub stars](https://img.shields.io/github/stars/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt)
[![GitHub forks](https://img.shields.io/github/forks/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt/fork) [![GitHub forks](https://img.shields.io/github/forks/dillonzq/LoveIt?style=social)](https://github.com/dillonzq/LoveIt/fork)
{{< /style >}}
[:(far fa-kiss-wink-heart fa-fw): LoveIt](https://github.com/dillonzq/LoveIt) 是一个由 [Dillon](https://dillonzq.com) 开发的**简洁**、**优雅**且**高效**的 [Hugo](https://gohugo.io/) 博客主题。 [:(far fa-kiss-wink-heart fa-fw): LoveIt](https://github.com/dillonzq/LoveIt) 是一个由 [Dillon](https://dillonzq.com) 开发的**简洁**、**优雅**且**高效**的 [Hugo](https://gohugo.io/) 博客主题。

View File

@@ -206,12 +206,12 @@ Note that some of these parameters are explained in details in other sections of
# {{< version 0.2.0 >}} App icon config # {{< version 0.2.0 >}} App icon config
[params.app] [params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher # optional site title override for the app when added to an iOS home screen or Android launcher
title = "LoveIt App" title = "LoveIt"
# whether to omit favicon resource links # whether to omit favicon resource links
noFavicon = true noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files # modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg' svgFavicon = ""
# Android browser color theming # Android browser theme color
themeColor = "#ffffff" themeColor = "#ffffff"
# Safari mask icon color # Safari mask icon color
iconColor = "#5bbad5" iconColor = "#5bbad5"

View File

@@ -211,12 +211,12 @@ Note that some of these parameters are explained in details in other sections of
# {{< version 0.2.0 >}} App icon config # {{< version 0.2.0 >}} App icon config
[params.app] [params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher # optional site title override for the app when added to an iOS home screen or Android launcher
title = "LoveIt App" title = "LoveIt"
# whether to omit favicon resource links # whether to omit favicon resource links
noFavicon = true noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files # modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg' svgFavicon = ""
# Android browser color theming # Android browser theme color
themeColor = "#ffffff" themeColor = "#ffffff"
# Safari mask icon color # Safari mask icon color
iconColor = "#5bbad5" iconColor = "#5bbad5"

View File

@@ -206,19 +206,19 @@ hugo
# {{< version 0.2.0 >}} 日期格式 # {{< version 0.2.0 >}} 日期格式
dateFormat = "2006-01-02" dateFormat = "2006-01-02"
# {{< version 0.2.0 >}} App icon config # {{< version 0.2.0 >}} 应用图标配置
[params.app] [params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher # 当添加到 iOS 主屏幕或者 Android 启动器时的标题, 覆盖默认标题
title = "LoveIt App" title = "LoveIt"
# whether to omit favicon resource links # 是否隐藏网站图标资源链接
noFavicon = true noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files # 更现代的 SVG 网站图标, 可替代旧的 .png .ico 文件
svgFavicon = 'favicon.svg' svgFavicon = ""
# Android browser color theming # Android 浏览器主题色
themeColor = "#ffffff" themeColor = "#ffffff"
# Safari mask icon color # Safari 图标颜色
iconColor = "#5bbad5" iconColor = "#5bbad5"
# Windows v8-10 tile color # Windows v8-10磁贴颜色
tileColor = "#da532c" tileColor = "#da532c"
# {{< version 0.2.0 >}} 搜索配置 # {{< version 0.2.0 >}} 搜索配置

View File

@@ -22,26 +22,30 @@ lightgallery: true
## style ## style
{{< version 0.2.0 changed >}}
`style` is a shortcode to insert custom style in your post. `style` is a shortcode to insert custom style in your post.
The `style` shortcode has two positional parameters. The `style` shortcode has two positional parameters.
The **first** one is the custom style content. The **first** one is the custom style content,
which supports nesting syntax in [SASS](https://sass-lang.com/documentation/style-rules/declarations#nesting)
and `&` referring to this parent HTML element.
And the **second** one is the HTML tag around the content you want to change style, and whose default value is `div`. And the **second** one is the tag name of the HTML element wrapping the content you want to change style, and whose default value is `div`.
Example `style` input: Example `style` input:
```markdown ```markdown
{{</* style "text-align: right;" */>}} {{</* style "text-align:right; strong{color:#00b1ff;}" */>}}
This is a right-aligned paragraph. This is a **right-aligned** paragraph.
{{</* /style */>}} {{</* /style */>}}
``` ```
The rendered output looks like this: The rendered output looks like this:
{{< style "text-align: right;" >}} {{< style "text-align:right; strong{color:#00b1ff;}" >}}
This is a right-aligned paragraph. This is a **right-aligned** paragraph.
{{< /style >}} {{< /style >}}
## link ## link

View File

@@ -27,26 +27,30 @@ Welcome to take the time to propose a translation by [making a PR](https://githu
## style ## style
{{< version 0.2.0 changed >}}
`style` is a shortcode to insert custom style in your post. `style` is a shortcode to insert custom style in your post.
The `style` shortcode has two positional parameters. The `style` shortcode has two positional parameters.
The **first** one is the custom style content. The **first** one is the custom style content,
which supports nesting syntax in [SASS](https://sass-lang.com/documentation/style-rules/declarations#nesting)
and `&` referring to this parent HTML element.
And the **second** one is the HTML tag around the content you want to change style, and whose default value is `div`. And the **second** one is the tag name of the HTML element wrapping the content you want to change style, and whose default value is `div`.
Example `style` input: Example `style` input:
```markdown ```markdown
{{</* style "text-align: right;" */>}} {{</* style "text-align:right; strong{color:#00b1ff;}" */>}}
This is a right-aligned paragraph. This is a **right-aligned** paragraph.
{{</* /style */>}} {{</* /style */>}}
``` ```
The rendered output looks like this: The rendered output looks like this:
{{< style "text-align: right;" >}} {{< style "text-align:right; strong{color:#00b1ff;}" >}}
This is a right-aligned paragraph. This is a **right-aligned** paragraph.
{{< /style >}} {{< /style >}}
## link ## link

View File

@@ -25,26 +25,29 @@ mapbox:
## style ## style
{{< version 0.2.0 changed >}}
`style` shortcode 用来在你的文章中插入自定义样式. `style` shortcode 用来在你的文章中插入自定义样式.
`style` shortcode 有两个位置参数. `style` shortcode 有两个位置参数.
第一个参数是自定义样式的内容. 第一个参数是自定义样式的内容. 它支持 [SASS](https://sass-lang.com/documentation/style-rules/declarations#nesting) 中的嵌套语法,
并且 `&` 指代这个父元素.
第二个参数是包裹你要更改样式的内容的 HTML 标签, 默认值是 `div`. 第二个参数是包裹你要更改样式的内容的 HTML 标签, 默认值是 `div`.
一个 `style` 示例: 一个 `style` 示例:
```markdown ```markdown
{{</* style "text-align: right;" */>}} {{</* style "text-align:right; strong{color:#00b1ff;}" */>}}
This is a right-aligned paragraph. This is a **right-aligned** paragraph.
{{</* /style */>}} {{</* /style */>}}
``` ```
呈现的输出效果如下: 呈现的输出效果如下:
{{< style "text-align: right;" >}} {{< style "text-align:right; strong{color:#00b1ff;}" >}}
This is a right-aligned paragraph. This is a **right-aligned** paragraph.
{{< /style >}} {{< /style >}}
## link ## link

View File

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

View File

@@ -1,4 +1,8 @@
{{- $content := .Inner | .Page.RenderString -}} {{- $content := .Inner | .Page.RenderString -}}
{{- $id := partial "function/id.html" (dict "content" $content) -}} {{- $id := partial "function/id.html" (dict "content" $content) -}}
{{- $tag := .Get 1 | default "div" -}} {{- $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>

View File

@@ -30,8 +30,7 @@
}, },
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "npm run build && npm run copy && git add .", "pre-commit": "npm run build && npm run copy && git add ."
"pre-push": "npm run build && npm run copy && git add ."
} }
}, },
"repository": { "repository": {

View File

@@ -0,0 +1 @@
#id-27e8e4 img{height:1.25rem}

View File

@@ -0,0 +1 @@
{"Target":"css/shortcode/style.css","MediaType":"text/css","Data":{}}