<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Shortcodes on FloatSheep&#39;s Blog</title>
    <link>/categories/shortcodes/</link>
    <description>Recent content in Shortcodes on FloatSheep&#39;s Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <copyright>© 2023 FloatSheep{{&lt; emoji id=&#34;footer-emoji&#34; data=&#34;thinking_face_color&#34; /&gt;}} &lt;br /&gt; 全站约 {{&lt; wordCount &#34;all&#34; &gt;}}</copyright>
    <lastBuildDate>Sat, 26 Aug 2023 10:10:04 +0800</lastBuildDate>
    <atom:link href="/categories/shortcodes/" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Hugo Shortcodes</title>
      <link>/posts/hugo-shortcodes/</link>
      <pubDate>Sat, 26 Aug 2023 10:10:04 +0800</pubDate>
      
      <guid>/posts/hugo-shortcodes/</guid>
      <description>
        &lt;h2 id=&#34;什么是-shortcodes&#34; class=&#34;relative group&#34;&gt;什么是 Shortcodes &lt;span class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100&#34;&gt;&lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34; style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e4%bb%80%e4%b9%88%e6%98%af-shortcodes&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Shortcodes（简码或短代码）&lt;/strong&gt; 是 &lt;strong&gt;Hugo&lt;/strong&gt; 为了避免内容作者因为 &lt;strong&gt;Markdown&lt;/strong&gt; 语法的不足而插入 &lt;strong&gt;HTML&lt;/strong&gt; 到内容中所创建的&lt;/p&gt;
&lt;p&gt;简单地说，&lt;strong&gt;Shortcodes&lt;/strong&gt; 就好比 &lt;strong&gt;Hexo&lt;/strong&gt; 中的 &lt;strong&gt;外挂标签（Tag Plugins）&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;我们可以随意的编写属于自己的 &lt;strong&gt;Shortcodes&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&#34;如何使用-shortcodes&#34; class=&#34;relative group&#34;&gt;如何使用 Shortcodes &lt;span class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100&#34;&gt;&lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34; style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-shortcodes&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;你使用的 &lt;strong&gt;Hugo Theme&lt;/strong&gt; 可能自带了一些 &lt;strong&gt;Shortcodes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;通过翻阅主题文档，我们可以通过简短的语法在 &lt;strong&gt;Markdown&lt;/strong&gt; 中使用这些 &lt;strong&gt;Shortcodes&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&#34;shortcodes-的调用方式&#34; class=&#34;relative group&#34;&gt;Shortcodes 的调用方式 &lt;span class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100&#34;&gt;&lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34; style=&#34;text-decoration-line: none !important;&#34; href=&#34;#shortcodes-%e7%9a%84%e8%b0%83%e7%94%a8%e6%96%b9%e5%bc%8f&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h3&gt;&lt;p&gt;我们可以通过&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;{{&amp;lt;&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;shortcodename&lt;/span&gt; &lt;span class=&#34;nx&#34;&gt;parameters&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;&amp;gt;}}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;直接调用短代码&lt;/p&gt;
&lt;h2 id=&#34;shortcodes-目录&#34; class=&#34;relative group&#34;&gt;Shortcodes 目录 &lt;span class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100&#34;&gt;&lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34; style=&#34;text-decoration-line: none !important;&#34; href=&#34;#shortcodes-%e7%9b%ae%e5%bd%95&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;编写 &lt;strong&gt;Shortcodes&lt;/strong&gt; 就像编写 &lt;strong&gt;Tag Plugins&lt;/strong&gt; 一样简单&lt;/p&gt;
&lt;p&gt;我们首先需要了解 &lt;strong&gt;Shortcodes&lt;/strong&gt; 目录&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Shortcodes&lt;/strong&gt; 目录位于 &lt;strong&gt;~/layouts/&lt;/strong&gt; 下,我们可以通过创建 &lt;strong&gt;HTML&lt;/strong&gt; 文件编写自己的 &lt;strong&gt;Shortcodes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;了解完目录，我们就可以尝试编写自己的 &lt;strong&gt;Shortcodes&lt;/strong&gt; 了&lt;/p&gt;
&lt;h2 id=&#34;编写-shortcodes&#34; class=&#34;relative group&#34;&gt;编写 Shortcodes &lt;span class=&#34;absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100&#34;&gt;&lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34; style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e7%bc%96%e5%86%99-shortcodes&#34; aria-label=&#34;Anchor&#34;&gt;#&lt;/a&gt;&lt;/span&gt;&lt;/h2&gt;&lt;p&gt;在  &lt;code&gt;~/layouts/shortcodes&lt;/code&gt;  下新建一个 &lt;strong&gt;HTML&lt;/strong&gt; 文件&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt; 文件的名称就是短代码的名称&lt;/p&gt;
&lt;p&gt;譬如:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;myShortcodes&lt;/li&gt;
&lt;li&gt;codeDemo&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;我们在 &lt;strong&gt;Markdown&lt;/strong&gt; 中写作时就可以通过 &lt;code&gt;{{&amp;lt; myShortcodes parameters &amp;gt;}}&lt;/code&gt; 的方式调用&lt;/p&gt;
&lt;p&gt;现在我们将它命名为 &lt;strong&gt;colorfont&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;






  
  
&lt;figure&gt;&lt;img src=&#34;https://dogefs.s3.ladydaily.com/hajeekn/storage/202308261042959.png&#34; alt=&#34;image-20230826104235937&#34; class=&#34;mx-auto my-0 rounded-md&#34; /&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;我们在里面写一段简单的 &lt;strong&gt;HTML&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;让我们可以通过 &lt;code&gt;color=colorname&lt;/code&gt; 的方式传参给 &lt;strong&gt;Shortcodes&lt;/strong&gt;，所以我们使用  &lt;code&gt;{{ with .Get &amp;quot;color&amp;quot; }}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;






  
  
&lt;figure&gt;&lt;img src=&#34;https://dogefs.s3.ladydaily.com/hajeekn/storage/202308261048844.png&#34; alt=&#34;image-20230826104800765&#34; class=&#34;mx-auto my-0 rounded-md&#34; /&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;接着，我们使用 &lt;strong&gt;Shortcodes&lt;/strong&gt; 让文字变红，这时候，我们就需要使用 &lt;code&gt;{{ .Inner }}&lt;/code&gt; 来获取我们传给 &lt;strong&gt;Shortcodes&lt;/strong&gt; 的文字&lt;/p&gt;
&lt;p&gt;






  
  
&lt;figure&gt;&lt;img src=&#34;https://dogefs.s3.ladydaily.com/hajeekn/storage/202308261051551.png&#34; alt=&#34;image-20230826105125474&#34; class=&#34;mx-auto my-0 rounded-md&#34; /&gt;
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;这样我们就完成了一个简单的 &lt;strong&gt;Shortcodes&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;来试试效果吧！&lt;/p&gt;
&lt;p&gt;在 &lt;strong&gt;Markdown&lt;/strong&gt; 中使用 &lt;code&gt;{{&amp;lt; colorfont color=&amp;quot;red&amp;quot; &amp;gt;}} Content {{&amp;lt;/ colorfont &amp;gt;}}&lt;/code&gt; 来调用&lt;/p&gt;
&lt;p style=&#34;color: red&#34;&gt; Content &lt;/p&gt;
&lt;p&gt;看，成功了！&lt;/p&gt;
&lt;p&gt;它还有更多用法，比如插入一个 &lt;strong&gt;Emoji&lt;/strong&gt;&lt;/p&gt;
&lt;img loading=&#34;lazy&#34; class=&#34;emoji-object&#34;  src=&#34;https://api.hesiy.cn/api/emoji?emoji=face_with_tongue_color&#34; type=&#34;image/svg+xml&#34;&gt;&lt;/img&gt;
&lt;p&gt;我们还可以将它们融合在一起&lt;/p&gt;
&lt;p style=&#34;color: green&#34;&gt; 泰库拉！&lt;img loading=&#34;lazy&#34; class=&#34;emoji-object&#34;  src=&#34;https://api.hesiy.cn/api/emoji?emoji=smiling_face_with_sunglasses_color&#34; type=&#34;image/svg+xml&#34;&gt;&lt;/img&gt;&lt;/p&gt;
&lt;p&gt;它还有许多的用法，就等各位去一一发掘了&lt;/p&gt;
&lt;div class=&#34;flex rounded-md bg-primary-100 px-4 py-3 dark:bg-primary-900&#34;&gt;
  &lt;span class=&#34;pe-3 text-primary-400&#34;&gt;
    &lt;span class=&#34;icon relative inline-block px-1 align-text-bottom&#34;&gt;&lt;svg xmlns=&#34;http://www.w3.org/2000/svg&#34; viewBox=&#34;0 0 512 512&#34;&gt;&lt;path fill=&#34;currentColor&#34; d=&#34;M506.3 417l-213.3-364c-16.33-28-57.54-28-73.98 0l-213.2 364C-10.59 444.9 9.849 480 42.74 480h426.6C502.1 480 522.6 445 506.3 417zM232 168c0-13.25 10.75-24 24-24S280 154.8 280 168v128c0 13.25-10.75 24-23.1 24S232 309.3 232 296V168zM256 416c-17.36 0-31.44-14.08-31.44-31.44c0-17.36 14.07-31.44 31.44-31.44s31.44 14.08 31.44 31.44C287.4 401.9 273.4 416 256 416z&#34;/&gt;&lt;/svg&gt;
&lt;/span&gt;
  &lt;/span&gt;
  &lt;span class=&#34;dark:text-neutral-300&#34;&gt;&lt;strong&gt;警告!&lt;/strong&gt; 如果你想要自定义 &lt;strong&gt;Shortcodes&lt;/strong&gt; 的样式，你应该在另外的 &lt;strong&gt;CSS&lt;/strong&gt; 文件中书写样式，你不应该在 &lt;strong&gt;Shortcodes&lt;/strong&gt; 文件中直接使用  &lt;code&gt;&amp;lt;style /&amp;gt;&lt;/code&gt; 语法，也不应该在 &lt;strong&gt;Shortcodes&lt;/strong&gt; 中引入样式，那将会浪费不必要的流量&lt;/span&gt;
&lt;/div&gt;


      </description>
    </item>
    
  </channel>
</rss>