Files
2018-10-02 00:21:50 +08:00

65 lines
2.2 KiB
HTML

<!-- Wikipedia link genertor shortcode for Hugo
Based on https://github.com/keltia/octopress/commit/17b975067ff86c0c7cddac4ae2c2c975b0790b6e
Author: Parsia Hakimian https://github.com/parsiya/Hugo-Shortcodes
-->
<!-- resetting scratch variables at the start -->
{{ $.Scratch.Set "wp_tag" "" }}
{{ $.Scratch.Set "wp_lang" "" }}
{{ $.Scratch.Set "wp_title" "" }}
{{ if .IsNamedParams }}
{{ $.Scratch.Set "wp_tag" (.Get "tag") }}
{{ with .Get "lang" }}
{{ $.Scratch.Set "wp_lang" . }}
{{ else }}
{{ $.Scratch.Set "wp_lang" "en" }}
{{ end }}
{{ with .Get "title" }}
{{ $.Scratch.Set "wp_title" . }}
{{ else }}
{{ $.Scratch.Set "wp_title" (.Get "tag") }}
{{ end }}
{{ else }}
{{ $.Scratch.Set "wp_tag" (.Get 0) }}
<!-- if all three attributes are provided -->
<!-- { { < wp VIC_Cipher "VIC Cipher" fr >}} -->
<!-- { { < wp VIC_Cipher "" fr >}} -->
{{ if len .Params | eq 3 }}
{{ $.Scratch.Set "wp_lang" (.Get 2) }}
<!-- if title is empty (2nd example) -->
{{ if len (.Get 1) | eq 0 }}
<!-- removing the underscore and converting it to space should be done here -->
{{ $.Scratch.Set "wp_title" (.Get 0) }}
{{ else }}
{{ $.Scratch.Set "wp_title" (.Get 1) }}
{{ end }}
{{ end }}
<!-- if only two attributes are provided -->
<!-- { { < wp VIC_Cipher fr >}} -->
<!-- { { < wp VIC_Cipher "VIC Cipher" >}} -->
{{ if len .Params | eq 2 }}
<!-- here I assume that if the length of the parameter is 2 then it's language otherwise title -->
{{ if len (.Get 1) | eq 2 }}
{{ $.Scratch.Set "wp_lang" (.Get 1) }}
<!-- removing the underscore and converting it to space should be done here -->
{{ $.Scratch.Set "wp_title" (.Get 0) }}
{{ else }}
{{ $.Scratch.Set "wp_lang" "en" }}
{{ $.Scratch.Set "wp_title" (.Get 1) }}
{{ end }}
{{ end }}
{{ if len .Params | eq 1 }}
{{ $.Scratch.Set "wp_lang" "en" }}
<!-- removing the underscore and converting it to space should be done here -->
{{ $.Scratch.Set "wp_title" (.Get 0) }}
{{ end }}
{{ end }}
<a href="https://{{ $.Scratch.Get "wp_lang" }}.wikipedia.org/wiki/{{ $.Scratch.Get "wp_tag" }}">{{ $.Scratch.Get "wp_title" }}</a>