From e3624bb9862f6b84a0e1c19285e60c4cf57e9881 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 26 Sep 2020 16:31:26 +0300 Subject: [PATCH] Add a `gh` shortcode --- site/layouts/shortcodes/gh.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 site/layouts/shortcodes/gh.html diff --git a/site/layouts/shortcodes/gh.html b/site/layouts/shortcodes/gh.html new file mode 100644 index 000000000..09a719694 --- /dev/null +++ b/site/layouts/shortcodes/gh.html @@ -0,0 +1,25 @@ +{{- /* + Usage: gh "foo", where foo can be: + + * "pr 1" -> #1 + * "issue 2" -> #2 + * "@XhmikosR" -> @XhmikosR + * "a3b09530fb31cfe6bd14d49965c19e8f89c1b023" -> a3b0953 + * "a3b0953" -> a3b0953 + + Quotes are not always needed, but Hugo can choke on some characters like @, in which case wrap the parameter with quotes. Also, they are needed for PR and Issue +*/ -}} + +{{ range .Params -}} + {{- if hasPrefix . "@" -}} + {{ . }} + {{- else if hasPrefix (. | lower) "pr" -}} + #{{ trim (substr . 2) " " }} + {{- else if hasPrefix (. | lower) "issue" -}} + #{{ trim (substr . (len "issue")) " " }} + {{- else if or (eq (len .) 7) (eq (len .) 40) -}} + {{ trim (substr . 0 7) " " }} + {{- else -}} + {{ errorf `Wrong parameter passed in %q shortcode: %s` $.Name $.Position }} + {{- end -}} +{{- end -}}