In this course I’ll walk you through the basics of writing your first extension.
If you want to see the extension I use as an example you can check out Static Site Hero.
This extension is super simple, but it solves a real world need I had. If you’ve seen my first Pluralsight course Build a Better Blog with a Static Site Generator, you know I use a static site generator to produce my blog. Static Site Hero helps me insert HTML figure structures into my markdown pages via a simple wizard.
I hope you enjoy my new course, and if you do please rate it to help other people find it!
First let’s look at the basic Markdown syntax for inserting an image:
So it’s just an exclamation point (or bang) followed by square braces and then parentheses.
This is essentially the same as a link, but with the addition of the exclamation point.
The two bits of info we need to add are the Alt Text and the image location.
The Alt Text goes inside the square braces and the link goes inside the parentheses.
If we look at the image at the top of this post what I see in my text editor is this:
![Sample Image Added via Markdown](/content/images/2015/12/sampleImage.jpg)
If you view source on my page what you would see is this:
<imgsrc="/content/images/2015/12/sampleImage.jpg"alt="Sample Image Added via Markdown">
So the next question is “Where the heck do I put the image??”.
The answer is actually “Wherever you like inside the source directory.”
In my case I have a structure inside my source directory that looks like this (pruned for clarity here):
│ │ └───2015
│ │ ├───01
│ │ ├───02
│ │ ├───07
│ │ ├───09
│ │ ├───10
│ │ ├───11
│ │ └───12
I put my static content inside a “content” directory because I picked up the habit while working with ASP MVC. You might choose to simply create an “img” directory.
Any directory that starts with an underscore (_data and _posts) will be either ignored (_data) or in the case of _posts, processed by Hexo (converted from Markdown to HTML for instance), but anything without an underscore will simply be copied to the output directory.
You can expand on that syntax a few ways.
I like to put my images inside <figure> tags, so the full bit I see is this:
<figureclass="left-align quarter-width">![Sample Image Added via Markdown](/content/images/2015/12/sampleImage.jpg)<figcaption>
This is a sample image added via Markdown in an HTML figure. Also, I got a new camera
and took a pretty cool picture of a helicopter.
Yes it looks crappy all run together on that first line, but if you put in linebreaks Hexo’s Markdown to HTML conversion will add in extra <br/> tags and screw up your layout.
One last thing I often do is make the image itself into a link.
This one gets messy, so hold on… We’ll make it simply link to the full image itself.
[![Sample Image Added via Markdown](/content/images/2015/12/sampleImage.jpg)](/content/images/2015/12/sampleImageFullSize.jpg)
And here is the result:
The messy part you see is that the entire image syntax goes inside the link’s square brackets.
That is very easy to get wrong. This is another bit where using your text editor’s snippet functionality can help (covered in Module 6 of my course).
I hope this helps! Let me know in the comments if you have any questions.