Anyone know of a short code or method to allow for Hugo to generate a citation for a blog post, for example, it would use data from the YAML or something and generate a citation so others could cite the blog post?
Hi @zad, we need more info in order to help you. What format would the citation be in? What does the YAML look like that it would created from? Give a concrete example if you can.
Hi, preferably the YAML would contain basic info such as a Title, Author, Date, URL and something like the APA format would be created?
Ex: Lastname, Firstname (year, month, day). Title. URL
This seems doable from a shortcode (as long as all that YAML data is populated in front matter).
Thanks, that gives me some hope. Any ideas on how to go about it? Still struggling a bit with shortcodes unfortunately
Give an actual example with output, please. Currently, I don’t understand if you want a shortcode to reference a different post, or to generate a reference at the place of the shortcode for the post it is published in. What do it look like when it renders as a page?
to generate a reference at the place of the shortcode for the post it is published in.
Yup, this is exactly it. A shortcode would be inserted, and in its place, a citation produced for that post.
any suggestions @zwbetz?
I’m not at my laptop now, but once I am I’ll see what I can do.
Thanks! I appreciate it!
Using blog post APA format: http://www.easybib.com/reference/guide/apa/website
Given this front matter, and this shortcode usage:
---
title: "Some Blog Title"
date: 2019-06-01T21:47:03-05:00
---
{{< cite last_name="Smith" first_name_initial="J" >}}
And this shortcode definition:
{{ $last_name := .Get "last_name" }}
{{ $first_name_initial := .Get "first_name_initial" }}
{{ $date_format := "2006, Jan 2" }}
{{ $publish_date := .Page.PublishDate.Format $date_format }}
{{ $title := .Page.Title }}
{{ $retrieve_date := now.Format $date_format }}
{{ $permalink := .Page.Permalink }}
<p>
{{ printf "%s, %s. (%s). %s. Retrieved %s, from %s" $last_name $first_name_initial $publish_date $title $retrieve_date $permalink }}
</p>
It will output:
<p>
Smith, J. (2019, Jun 1). Some Blog Title. Retrieved 2019, Jun 14, from http://example.org/
</p>
@zwbetz put that together for ya, and it will work. But I want to suggest a different way: rather than a shortcode, incorporate @zwbetz’s example into a partial template and have it add to the page based on a front matter parameter. Ultimately, less typing.
Wow! Thanks so much! I’ll give this a try and report back!
@maiki, I’ll also give that a try and see how it goes
Here’s what I ended up using.
The markdown file has this front matter:
title: "Generic Title"
author:
first_name: Zad
first_name_initial: Z
middle_name_initial: R
last_name: Chow
date: '2018-04-03'
With the partial file having these contents
{{ $last_name := .Param "author.last_name" }}
{{ $first_name := .Param "author.first_name" }}
{{ $first_name_initial := .Param "author.first_name_initial" }}
{{ $middle_name_initial := .Param "author.middle_name_initial" }}
{{ $APAdate_format := "2006, Jan 2" }}
{{ $APApublish_date := .Page.PublishDate.Format $APAdate_format }}
{{ $AMAdate_format := "January 2, 2006" }}
{{ $AMApublish_date := .Page.PublishDate.Format $AMAdate_format }}
{{ $MLAdate_format := " 2 Jan. 2006" }}
{{ $MLApublish_date := .Page.PublishDate.Format $MLAdate_format }}
{{ $title := .Page.Title }}
{{ $permalink := .Page.Permalink }}
<b>APA:</b> {{ printf "%s, %s. %s. (%s). %s. Retrieved from %s." $last_name $first_name_initial $middle_name_initial $APApublish_date $title $permalink }}
<b>AMA:</b> {{ printf "%s, %s%s. %s. Less Likely. %s. Published %s." $last_name $first_name_initial $middle_name_initial $title $permalink $AMApublish_date }}
<b>MLA:</b> {{ printf "%s, %s. %s. %s. Less Likely. %s. %s." $last_name $first_name $middle_name_initial $title $permalink $MLApublish_date }}
and the end product (mine is formatted to come out with a pop-up box):
Thank You for posting a summary!