Hugo shortcoeds示例
2019年2月27日
约 4149 字 需时 9 分钟
深色阅读
神器shortcodes的横空出世,让hugo一举超越hexo,神奇程度不亚于当年total commander的插件系统。下面,介绍自己在用的近二十个shortcodes。
视频简码(video.html)
如果想让页面加载本地视频文件,你的视频文件可以放在hugo站点下的 static/img/
媒体目录,也可以放置在你的页面目录
, 然后,按照以下2种形式援引路径来调用。
媒体目录
{{% video src="/img/video/videojs.mp4" controls="yes" %}}
效果如下:
页面目录
比如,视频在 content/post/hello/
目录下:
{{< video src="my_video.mp4" controls="yes" >}}
在线视频
除了通过简码可以自定义加载本地视频,hugo还内置了youtube、vimeo、Twitter、Instagram等加载在线视频的简码,当然在国内被墙了,访问不了。
Youtube:
{{< youtube w7Ft2ymGmfc >}}
效果如下(需要翻墙查看):
Vimeo:
{{< vimeo 146022717 >}}
{{< tweet 877500564405444608 >}}
{{< instagram BWNjjyYFxVx hidecaption >}}
bilibili
{{< bilibili aid="63014656" >}}
wikipedia
{{< wp tag="膜蛤文化" lang="zh" title="《神秘的膜蛤文化》" >}}
或者简化版
{{< wp 膜蛤文化 "《神秘的膜蛤文化》" zh >}}
《神秘的膜蛤文化》
豆瓣
{{< douban ID >}}
此处的ID是电影的IMDB号(失效,官方已下架api)或者书籍的ISBN序列号
效果如下:
注意:豆瓣自18年开始即启用referrer筛除防盗链,所以为了避免出现无法显示海报或者书籍封面的情形,建议在header.html增加下列meta标签,但这样做又会影响aplayer的显示,两权其害取其轻者,在想出完美方案之前只能牺牲图片显示了。
<meta name="referrer" content="never">
嵌入文档(gdocs.html)
为了将google 文档嵌入页面,你首先要通过 文件 >发布 > 嵌入得到一段iframe代码,将其中的src=““的链接复制粘贴出来即可。
{{< gdocs src="https://docs.google.com/document/d/e/2PACX-1vTAQPJ1wIH4OWoI3OKV2LIl8xUUwAg8ngQGcHd6VF3x8EYfRX5jLg6x2SuHhaaqVOmV_tvFvtYEqJcZ/pub?embedded=true" >}}
效果如下(需要翻墙查看):
imgur
为了避免特定的敏感图片被国内ISP审察,我们可以将imgur作为上传图床,随后引用置入帖子中,以https://imgur.com/a/ZT8fImy
为例
{{< imgur id="ZT8fImy" >}}
简易版文本居中
{{< center >}}
引用文本
#除去首位两行,每行行末加<br>
{{< center >}}
《从前慢》 木心
记得早先少年时
大家诚诚恳恳
说一句 是一句
清早上火车站
长街黑暗无行人
卖豆浆的小店冒着热气
从前的日色变得慢
车,马,邮件都慢
一生只够爱一个人
从前的锁也好看
钥匙精美有样子
你锁了 人家就懂了
记得早先少年时
大家诚诚恳恳
说一句 是一句
清早上火车站
长街黑暗无行人
卖豆浆的小店冒着热气
从前的日色变得慢
车,马,邮件都慢
一生只够爱一个人
从前的锁也好看
钥匙精美有样子
你锁了 人家就懂了
pdf内嵌展示
{{< pdf src="**.pdf" >}}
相对地址效果:
绝对地址效果:
声享PPT(shengxiang.html)
引入 声享 PPT 演示文稿,
{{% shengxiang "a8a49a00" "dark" %}}
Image caption(imgcap.html)
{{< imgcap title="戏鸟图" src="https://ian2.oss-cn-hangzhou.aliyuncs.com/clt6/20190212115749.png" >}}

HTML4 Audio Widget(audio.html)
参数
- src - (required) Address of the audio file
- type - (required) Audio encoding(mp3, ogg, etc)
- preload - Should the audio be preloaded when the page loads Valid values are: “none”, “metadata”, and “auto” Default is set to “metadata”
- title - Title of audio track
- attr - Attribution
- attr_link - Link to attribution
- year - Year the audio was produced
- artist - Artist of the audio
- album_title - Title of the album
- album_art - Link to the album art
- label - Record label
- class - Class attribute of the audio element By default it contains “audio_controls”
- id - Id attribute of the audio element
- style - Style attribute of the audio element
- width - Width of HTML5 audio control widget
- height - Height of HTML5 audio control widget
{{< audio src="/audio/Beep.mp3" artist="windows" tile="Beep" >}}
vega-lite
{{< vega id="viz" spec="/post/Hugo shortcodes.files/vegalite.json" >}}