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

Commit

Permalink
feat(style): improve style shortcode to support nesting (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq authored Apr 26, 2020
1 parent f8b84de commit fc46fba
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 63 deletions.
5 changes: 5 additions & 0 deletions assets/css/_mixin/_summary.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
padding: 30% 0 0;
position: relative;
margin: 0.6rem auto;
@include transition(transform 0.4s ease);

img {
position: absolute;
Expand All @@ -24,6 +25,10 @@
top: 0;
object-fit: cover;
}

&:hover {
@include transform(scale(1.01));
}
}

.single-title {
Expand Down
36 changes: 18 additions & 18 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ enableEmoji = true
# App icon config
[languages.en.params.app]
# 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
noFavicon = true
noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg'
# Android browser color theming
svgFavicon = ""
# Android browser theme color
themeColor = "#ffffff"
# Safari mask icon color
iconColor = "#5bbad5"
Expand Down Expand Up @@ -284,19 +284,19 @@ enableEmoji = true
description = "关于 LoveIt 主题"
# 网站关键词
keywords = ["Theme", "Hugo"]
# App icon config
# 应用图标配置
[languages.zh-cn.params.app]
# optional site title override for the app when added to an iOS home screen or Android launcher
title = "LoveIt App"
# whether to omit favicon resource links
noFavicon = true
# modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg'
# Android browser color theming
# 当添加到 iOS 主屏幕或者 Android 启动器时的标题, 覆盖默认标题
title = "LoveIt"
# 是否隐藏网站图标资源链接
noFavicon = false
# 更现代的 SVG 网站图标, 可替代旧的 .png .ico 文件
svgFavicon = ""
# Android 浏览器主题色
themeColor = "#ffffff"
# Safari mask icon color
# Safari 图标颜色
iconColor = "#5bbad5"
# Windows v8-10 tile color
# Windows v8-10 磁贴颜色
tileColor = "#da532c"
# 搜索配置
[languages.zh-cn.params.search]
Expand Down Expand Up @@ -472,12 +472,12 @@ enableEmoji = true
# App icon config
[languages.fr.params.app]
# 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
noFavicon = true
noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg'
# Android browser color theming
svgFavicon = ""
# Android browser theme color
themeColor = "#ffffff"
# Safari mask icon color
iconColor = "#5bbad5"
Expand Down
2 changes: 2 additions & 0 deletions exampleSite/content/about.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ math:
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)
[![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)
[![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)
{{< /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).

Expand Down
2 changes: 2 additions & 0 deletions exampleSite/content/about.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ math:
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)
[![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)
[![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)
{{< /style >}}

{{< admonition warning >}}
Sorry, this article has not been completely translated into **French**.
Expand Down
2 changes: 2 additions & 0 deletions exampleSite/content/about.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ math:
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)
[![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)
[![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)
{{< /style >}}

[:(far fa-kiss-wink-heart fa-fw): LoveIt](https://github.com/dillonzq/LoveIt) 是一个由 [Dillon](https://dillonzq.com) 开发的**简洁****优雅****高效**[Hugo](https://gohugo.io/) 博客主题。

Expand Down
8 changes: 4 additions & 4 deletions exampleSite/content/posts/theme-documentation-basics.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[params.app]
# 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
noFavicon = true
noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg'
# Android browser color theming
svgFavicon = ""
# Android browser theme color
themeColor = "#ffffff"
# Safari mask icon color
iconColor = "#5bbad5"
Expand Down
8 changes: 4 additions & 4 deletions exampleSite/content/posts/theme-documentation-basics.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[params.app]
# 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
noFavicon = true
noFavicon = false
# modern SVG favicon to use in place of older style .png and .ico files
svgFavicon = 'favicon.svg'
# Android browser color theming
svgFavicon = ""
# Android browser theme color
themeColor = "#ffffff"
# Safari mask icon color
iconColor = "#5bbad5"
Expand Down
20 changes: 10 additions & 10 deletions exampleSite/content/posts/theme-documentation-basics.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,19 @@ hugo
# {{< version 0.2.0 >}} 日期格式
dateFormat = "2006-01-02"

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

# {{< version 0.2.0 >}} 搜索配置
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ lightgallery: true

## style

{{< version 0.2.0 changed >}}

`style` is a shortcode to insert custom style in your post.

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:

```markdown
{{</* style "text-align: right;" */>}}
This is a right-aligned paragraph.
{{</* style "text-align:right; strong{color:#00b1ff;}" */>}}
This is a **right-aligned** paragraph.
{{</* /style */>}}
```

The rendered output looks like this:

{{< style "text-align: right;" >}}
This is a right-aligned paragraph.
{{< style "text-align:right; strong{color:#00b1ff;}" >}}
This is a **right-aligned** paragraph.
{{< /style >}}

## link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@ Welcome to take the time to propose a translation by [making a PR](https://githu

## style

{{< version 0.2.0 changed >}}

`style` is a shortcode to insert custom style in your post.

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:

```markdown
{{</* style "text-align: right;" */>}}
This is a right-aligned paragraph.
{{</* style "text-align:right; strong{color:#00b1ff;}" */>}}
This is a **right-aligned** paragraph.
{{</* /style */>}}
```

The rendered output looks like this:

{{< style "text-align: right;" >}}
This is a right-aligned paragraph.
{{< style "text-align:right; strong{color:#00b1ff;}" >}}
This is a **right-aligned** paragraph.
{{< /style >}}

## link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,29 @@ mapbox:

## style

{{< version 0.2.0 changed >}}

`style` shortcode 用来在你的文章中插入自定义样式.

`style` shortcode 有两个位置参数.

第一个参数是自定义样式的内容.
第一个参数是自定义样式的内容. 它支持 [SASS](https://sass-lang.com/documentation/style-rules/declarations#nesting) 中的嵌套语法,
并且 `&` 指代这个父元素.

第二个参数是包裹你要更改样式的内容的 HTML 标签, 默认值是 `div`.

一个 `style` 示例:

```markdown
{{</* style "text-align: right;" */>}}
This is a right-aligned paragraph.
{{</* style "text-align:right; strong{color:#00b1ff;}" */>}}
This is a **right-aligned** paragraph.
{{</* /style */>}}
```

呈现的输出效果如下:

{{< style "text-align: right;" >}}
This is a right-aligned paragraph.
{{< style "text-align:right; strong{color:#00b1ff;}" >}}
This is a **right-aligned** paragraph.
{{< /style >}}

## link
Expand Down
8 changes: 4 additions & 4 deletions layouts/partials/head/link.html
Original file line number Diff line number Diff line change
@@ -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">
Expand Down
6 changes: 5 additions & 1 deletion layouts/shortcodes/style.html
Original file line number Diff line number Diff line change
@@ -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>
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
},
"husky": {
"hooks": {
"pre-commit": "npm run build && npm run copy && git add .",
"pre-push": "npm run build && npm run copy && git add ."
"pre-commit": "npm run build && npm run copy && git add ."
}
},
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#id-27e8e4 img{height:1.25rem}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Target":"css/shortcode/style.css","MediaType":"text/css","Data":{}}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit fc46fba

Please sign in to comment.