Skip to content

Commit 076c9eb

Browse files
committed
✨ Feat: add codepen shortcode and replace raw html in previous posts.
1 parent c391e96 commit 076c9eb

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

content/posts/2016-07-25-jquery-f.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ isCJKLanguage: true
2121
本来觉得 jsFiddle 长得比较小清新, 更好看些, 可是实际用下来竟然觉得 CodePen 更好用. 主要两个地方不爽jsFiddle, 一是经常很卡打开很慢, 二是添加 external resources 的时候竟然要求一定要 CDN 的. 另外 CodePen 有个可以自由选取预处理器的功能比jsFiddle也方便一些. 抽时间做个自己的 CodePen theme*
2222

2323

24-
<p data-height="606" data-theme-id="0" data-slug-hash="zBjLwQ" data-default-tab="js,result" data-user="bambooom" data-embed-version="2" class="codepen">See the Pen <a href="http://codepen.io/bambooom/pen/zBjLwQ/">zBjLwQ</a> by bamboo (<a href="http://codepen.io/bambooom">@bambooom</a>) on <a href="http://codepen.io">CodePen</a>.</p>
25-
<script async src="//assets.codepen.io/assets/embed/ei.js"></script>
24+
{{< codepen bambooom zBjLwQ >}}
2625

2726

2827
## stuck in radio....?!

content/posts/2018-04-11-elementfrompoint-text-element.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ isCJKLanguage: true
99

1010
捉 bug 记录一个 case
1111

12-
13-
<p data-height="300" data-theme-id="33133" data-slug-hash="aYMYpE" data-default-tab="result" data-user="bambooom" data-embed-version="2" data-pen-title="elementFromPoint with text element" class="codepen">See the Pen <a href="https://codepen.io/bambooom/pen/aYMYpE/">elementFromPoint with text element</a> by bamboo (<a href="https://codepen.io/bambooom">@bambooom</a>) on <a href="https://codepen.io">CodePen</a>.</p>
14-
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
15-
12+
{{< codepen bambooom aYMYpE >}}
1613

1714
## Question
1815

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{{/* CodePen shortcode. */}}
2+
{{/* Parameters : */}}
3+
{{/* - user (#0) : the user ID. */}}
4+
{{/* - id (#1) : the code ID (hash). */}}
5+
{{/* - theme : light or dark. */}}
6+
{{/* - defaultTabs: default tabs separated by comma, html, js, css and result, default to "html,result". */}}
7+
{{/* - height : frame height, default to 300. */}}
8+
{{- $user := "" }}
9+
{{- $id := "" }}
10+
{{- $theme := "" }}
11+
{{- $defaultTabs := "html,result" }}
12+
{{- $height := 300 }}
13+
{{- if .IsNamedParams }}
14+
{{- $user = .Get "user" }}
15+
{{- $id = .Get "id" }}
16+
{{- with .Get "theme" }}{{ $theme = . }}{{ end }}
17+
{{- with .Get "defaultTabs" }}{{ $defaultTabs = . }}{{ end }}
18+
{{- with .Get "height" }}{{ $height = . }}{{ end }}
19+
{{- else }}
20+
{{- $user = .Get 0 }}
21+
{{- $id = .Get 1 }}
22+
{{- end }}
23+
{{- $src := printf
24+
"https://codepen.io/%s/embed/%s?default-tab=%s"
25+
$user
26+
$id
27+
$defaultTabs
28+
}}
29+
{{- with $theme }}
30+
{{- $src = printf "%s&theme-id=%s" $src . }}
31+
{{- end }}
32+
<iframe
33+
width="100%"
34+
height="{{ $height }}"
35+
style="width: 100%;"
36+
title="Hello World!"
37+
src="{{ $src }}"
38+
frameborder="no"
39+
loading="lazy"
40+
allowtransparency="true"
41+
allowfullscreen="true">
42+
</iframe>

0 commit comments

Comments
 (0)