Hacking VS Code: My New Pluralsight Course

My Caption

Hacking Visual Studio Code

Every programmer needs a good text editor he or she can extend.

Microsoft’s new text editor Visual Studio Code is just such an editor.

Of course getting started writing extensions for any text editor can be a bit daunting.

That’s why I made my new Pluralsight course Hacking VS Code: Writing Your First Extension for Visual Studio Code.

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!

This Changes Everything: Xamarin Tools Are Now Free!

Scott Guthrie
Scott Guthrie
This is HUGE, no kidding.

For several years now Xamarin has provided an excellent set of tools that let you write mobile apps in one language, C#, then compile it to native apps on each platform.

Many of us believed this was the best approach for mobile, but couldn’t justify the pricetag for the Xamarin stack.

Guess what?

Microsoft bought Xamarin and announced at the Build Conference this week that not only is the pricetag becoming “Free” the source itself is becoming “Free”.

That’s right free as in beer and free as in liberty.

Boom.

Even more amazingly they will be included with Visual Studio’s Community Edition which is also free (at least as in beer).

I really do think this will change the way people build mobile apps.

Why on earth would I write an iOS app and an Android app that share no code?

I’ve loved the C# language for years, and now there’s no reason I can’t use it to write all my mobile apps.

Build a Better Blog With a Static Site Generator

Slide Deck

Slide Deck from my talk. Download Here

These are the slides from a talk about setting up a blog with a static website generator that I gave first to GGMUG
and then the Atlanta .Net User Group.

I also did a workshop based on this content for the Atlanta Windows Apps group.

If you want a full, step-by-step course on getting your blog set up with a
static website generator, you can check out
my course on Pluralsight:
Build a Better Blog with a Static Site Generator

Adding Images to a Hexo Post via Markdown

Sample Image Added via Markdown

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.

Maher Jendoubi asked how to add images to a Hexo blog post via Markdown.

Rather than try to post the answer in the comments of my course
Build a Better Blog with a Static Site Generator, I thought
I’d do so via a blog post so that I could go into more detail.

First let’s look at the basic Markdown syntax for inserting an image:

1
![]()

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:

1
![Sample Image Added via Markdown](/content/images/2015/12/sampleImage.jpg)

If you view source on my page what you would see is this:

1
<img src="/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):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
├───content
│ ├───images
│ │ └───2015
│ │ ├───01
│ │ ├───02
│ │ ├───07
│ │ ├───09
│ │ ├───10
│ │ ├───11
│ │ └───12
│ └───presentations
│ └───2015
│ ├───02
│ ├───07
│ ├───10
│ └───11
├───_data
└───_posts

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:

1
2
3
4
5
<figure class="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.
</figcaption>
</figure>

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.

1
[![Sample Image Added via Markdown](/content/images/2015/12/sampleImage.jpg)](/content/images/2015/12/sampleImageFullSize.jpg)

And here is the result:

Sample Image Added via Markdown

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.

Using Hexo Data Files

Alt Text

Learn how to use Hexo’s Data Files.

If you have some data you’d like to load from a file and use to generate a widget
for your Hexo blog, Data Files are just the ticket.

Or rather they would be if they worked.

Scratch that… they actually work just fine, but the documentation is kind of wrong (as of
the time I’m writing this at least).

The idea is that you can create either a YAML or JSON file and store it in a directory
called _data in your source directory, then spin through all the items in it in code.

Here’s what the docs show:

1
2
3
{% for link in site.data.menu %}
<a href="{{ link }}">{{ loop.key }}</a>
{% endfor %}

One of the comments says that the listed code works for Swig, but since everything else is
documented for EJS it is a bit confusing.

So let’s make a widget that uses a Data File successfully.

That’s exactly how I implemented my blog’s Popular Posts widget.

The first thing we need is a file with data.

Since I have some characters that don’t play well with YAML, I have to wrap everything
up in quotes.

My current file (popularposts.yml) looks like this:

1
2
3
4
5
6
7
8
9
10
"Formatted JSON in Notepad++": "/formatted-json-in-notepad/"
"Is It Hot In Here Or Is It Just My CPU?": "/is-it-hot-in-here-or-is-it-just-my-cpu/"
"DIY Productivity Tablet": "/diy-productivity-tablet/"
"Teaching PowerShell To Speak": "/teaching-powershell-to-speak/"
"Kindle To Raspberry Pi Via Remote Desktop": "/kindle-to-raspberry-pi-via-remote-desktop/"
"Configure Raspberry Pi As WiFi Router": "/configure-raspberry-pi-as-wifi-router/"
"Formatted JSON In Notepad++ Video": "/formatted-json-in-notepad-video/"
"My Secret Weapon: Pluralsight": "/my-secret-weapon-pluralsight/"
"Vim Eye For The Visual Studio Guy": "/vim-eye-for-the-visual-studio-guy/"
"Visual Studio Tip: Add Existing Directory": "/visual-studio-tip-add-existing-directory-aspx/"

If you’ve read my last post Creating a Hexo Widget,
then you know that the base of a widget is this:

1
2
3
4
5
6
7
8
<% if (someConditionalIsTrue){ %>
<div class="widget-wrap">
<h3 class="widget-title">Your Widget Title Here</h3>
<div class="widget">
Your widget content here.
</div>
</div>
<% } %>

So we just need to adapt that and replace “Your widget content here” with code to spin through our list and spit out links.

Here’s what my popularposts.ejs looks like:

1
2
3
4
5
6
7
8
9
10
11
12
<% if(site.data.popularposts) {%>
<div class="widget-wrap">
<h3 class="widget-title">Popular Posts</h3>
<div class="widget">
<ol class="numbered-list">
<% for (item in site.data.popularposts) { %>
<li><a href="<%= site.data.popularposts[item] %>"><%= item %></a></li>
<% } %>
</ol>
</div>
</div>
<% } %>

As you can see the concept is the same, just the syntax is different.

On the first line you can see how to reference your data.

site.data.popularposts where “popularposts.yml” is the file name.

On line 6 you can see how to implement a for loop over the data items, and
on line 7 you can see how to reference both the keys and values.

It’s not really difficult and it works well, so it’s a shame the docs are confusing
people.

If you’d like a complete walkthrough of how to set up your blog with either Hexo
or DocPad, be sure to check out my Pluralsight course
Build a Better Blog with a Static Site Generator.

I’ll walk you through everything from installing Hexo to prettying up the Landscape theme
to adding comments with Disqus and deploying with Git.