Skip to main content
  1. Posts/

Hugo Stock Summary ShortCode Module

·380 words·2 mins·
Yaheya Quazi
Author
Yaheya Quazi
Indeed, the mercy of Allah is near to the doers of good.

If you are a regular visitor of my site, you may have noticed, I have started posting daily closing bell stock market summary. These pages proceeds with a Market index summary from that day. Let’s discuss how I put it together.

What is a Hugo ShortCode?

Shortcodes are simple snippets inside your content files calling built-in or custom templates.

Parts of the Stock Summary ShortCode

  1. A JSON Payload for each day to summarize the data.
  2. ShortCode HTML
  3. Insertion of the ShortCode into any Mark Down file.

Below is a sample JSON Payload that the Short Code uses -

{
"Index1": {
"name": "Dow",
"value": "30946.99",
"change": "-491.27",
"percentage": "-1.56"
},
"Index2": {
"name": "S&P 500",
"value": "3821.55",
"change": "-78.56",
"percentage": "-2.01"
},
"Index3": {
"name": "Nasdaq",
"value": "11181.54",
"change": "-343.01",
"percentage": "-2.98"
},
"Index4": {
"name": "Russel 2K",
"value": "1738.84",
"change": "-32.90",
"percentage": "-1.86"
},
"Index5": {
"name": "VIX",
"value": "28.36",
"change": "1.41",
"percentage": "5.23"
}

}

Copy the above payload and call it stocks06282022.json. Place this file under your Data folder in Hugo project.

Create a file called stocks.html and place the following html in it. Save the file under your layout\shortcodes folder

<h3>Market Summary</h3>
<table class="table table-dark">
    <thead>
         <tr>
        <th scope="col">Index</th>
        <th scope="col">Value</th>
        <th scope="col">Change</th>
        <th scope="col">Percentage</th>
      </tr>
    </thead>
    <tbody>
      {{ $filename := .Get "file" }}
      {{ range index .Site.Data $filename }}
      <tr>
        <td>{{.name}}</td>
        <td>{{lang.FormatNumberCustom 2 .value}}</td>
        <td>{{lang.FormatNumberCustom 2 .change}}</td>
        <td>{{lang.FormatNumberCustom 2 .percentage}}</td>
      </tr>
      {{end}}
     </tbody>
  </table>

Note I am using bootstrap 4.1 to stylize my table, you can do the same or style it the way you see fit.

Ok we are now ready to use the ShortCode! Add the following markup where ever you want to display the stock market summary based on your JSON payload.

“{ { < stocks file=“stocks06282022” >} }”

Note the parameter the markdown file is passing to the ShortCode module. It is the file name. The trick is every day, you update your JSON file to a new file (call it whatever makes sense to you) save it in the Data folder, and then you get your summary displayed!

Stock Summary JSON payload can be accessed by this service. I am using it in my project.

http://api.marketstack.com/v1/exchanges?access_key=your-key&limit=3&offset=0

I hope this post was useful!

Repository

My entire site is available to public.

Related

Bing Image Gallery and Power Automate

·117 words·1 min
I downloaded the Bing wallpaper app. It is actually awesome, everyday I turn on my computer to see what kind of wall paper I get for that day. Most of these are amazing! I use them in my desktop and also as my zoom background! Finally, I created a small Power Automate routine, that downloads each day Bing wall paper and saves it on to my drive.

Yaheya.Com new site!

·93 words·1 min
After many years, moved my personal site to Hugo, previously DotNet Core Azure Web App. Details of current site can be found here Hugo which is the main platform this site runs under is a brilliant idea. Not all sites, needs to be generated off from a Database or need backend server technology.

Closing Bell 6-29-2022

·316 words·2 mins
Market Summary Index Value Change Percentage Dow 31,029.31 82.32 0.27 S&P 500 3,818.83 -2.72 -0.07 Nasdaq 11,177.89 -3.65 -0.03 Russel 2K 1,719.37 -24.79 -1.86 VIX 28.16 0.20 -0.71 A volatile day. Market is giving up slowly all the gains from last week.

Closing Bell 6-28-2022

·212 words·1 min
Market Summary Index Value Change Percentage Dow 30,946.99 -491.27 -1.56 S&P 500 3,821.55 -78.56 -2.01 Nasdaq 11,181.54 -343.01 -2.98 Russel 2K 1,738.84 -32.90 -1.86 VIX 28.36 1.41 5.23 Massive red days are back! All indices are in deep red territory with VIX surging back up above 28 again. Cathie Wood believes US is already in a recession. I think as the month June ends and the market wraps up one of the worst six months of the year in stock market history, we can start to see some uptrend.

Closing Bell 6-27-2022

·233 words·2 mins
Market Summary Index Value Change Percentage Dow 31,438.26 -62.42 -0.20 S&P 500 3,900.11 -11.63 -0.30 Nasdaq 11,524.55 -83.07 -0.72 Russel 2K 1,771.74 6.01 0.34 VIX 26.95 -0.28 -1.03 Not a green day but not that red either - which is surprising. A big run on Friday and last week, one would assume a massive pull back today - did not happen. Definitely a good sign. Russel 2K ended up green, which is usually indicator for the growth stocks. Read the following this weekend, wanted to share -

Closing Bell 6-24-2022

·331 words·2 mins
Market Summary Index Value Change Percentage Dow 31,500.68 832.32 2.68 S&P 500 3,911.74 375.43 3.34 Nasdaq 11,607.62 179.11 1.62 Russel 2K 1,765.74 54.07 3.16 VIX 27.23 -1.82 -6.27 Well I am happy to report my prediction for the day of the market was absolutely wrong. All major indices were massively green for the day. Solid gains in S&P, Dow and Nasdaq - what a relief.