在Hugo中折叠部分内容

in #cn7 years ago (edited)

之前疯狂粘贴自己的扩展 凑字数 的时候,我发现这种又臭又长的列表需要稍微隐藏一下。

我的博客使用的生成器 Hugo 并不原生支持折叠。所以,我利用 shortcode 功能自己写了一个。

Shortcode 的介绍在这里,主要难度在于go的html模板引擎。

折叠部分用了 HTML5 的新特性:<details>,不支持 edge,这个浏览器应该没有人用吧……

下面是shortcode的代码,放在/themes/<THEME>/layouts/shortcodes/spoiler.html下:

<details>
<summary>
  <h4>
    {{ with .Get 0}}{{.}}{{else}}click to expand{{ end }}
  </h4>
</summary>
{{.Inner}}
</details>

用法是这样的:

{{%spoiler "You killed my father!" %}}
I am your father.
NOOOOOOO!
{{% /spoiler %}}

当然,我还稍微改了一下CSS,在这里的78~92行。


这篇文章是先发在我的博客上的,解决的也是那里的问题。

那么,steemit上有没有这种功能呢?

Updated at 17-10-11:

Steemit 编辑器并不支持<details>tag,我可能要找一些别的办法……

Sort:  

Congratulations @heyeshuang! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You made your First Comment
Award for the number of upvotes received
Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

你好。今天是你来 steem 刚满一个月的日子。由于你在中文区发布过文章,中文区新人之家“希望工程”今天特别为你庆祝满月,请点击查看。新人之家欢迎你,欢迎参加这里举办的各种活动,并期待你在未来继续发布优质文章!

Hello. Today you have been on Steem for one month. You have contributed at least one post in CN community. The Welcome Center for New Steemians is having a celebration for you. Welcome to CN community. Looking forward for more high-quality posts from you in the future!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 64038.60
ETH 3148.89
USDT 1.00
SBD 3.97