chadbaldwin / chadbaldwin.github.io

The repo that drives my blog chadbaldwin.net
http://chadbaldwin.net
32 stars 38 forks source link

[Comments] Building a Free Blog with GitHub Pages in Minutes #11

Open chadbaldwin opened 3 years ago

chadbaldwin commented 3 years ago

https://chadbaldwin.net/2021/03/14/how-to-build-a-sql-blog.html

SarahLii commented 2 years ago

Thanks a lot! It`s really helpful!!!

jessieupp commented 2 years ago

thank you! is it easy to add comments to a blog post like this? :)

chadbaldwin commented 2 years ago

@jessieupp Hi! Sorry I didn't get back to you sooner. So I looked into this a bit for you, and the answer is yes! In my opinion, the best way to do it is to use GitHub issues for comments. Each blog post has an "Issue" assigned to it, and the comments show up on your post. Which is exactly how our comments to each other are working right now.

I'm not sure what type of blog you plan on writing, but since my blog is geared towards software/database developers, I'm okay with requiring my readers to have a GitHub account in order to leave a comment. If your blog is about something less technical, then you may want to find another option than this one.

I believe there are other options such as disqus, which may be more appropriate for a more universal blog, however, it's not free and would still require someone to register in order to leave a comment. If you decide to go that route and you're having trouble getting it to work with your site, feel free to reach out to me.


The comment system I was using on this site prior to your comment was just a simple script I found that someone else had written, it looked decent and it worked...but it required doing things like modifying your blogs configuration, manually creating a GitHub issue, linking it to your post, etc.

While looking into this, I came across a popular GitHub app called utterances. It's almost identical to the comments section I was using before, but with WAY more features, and its all automatic. I no longer have to manually create GitHub issues, and best of all, it was relatively easy to set up. So I decided to make the switch, thanks to you! haha

I would recommend checking it out here: https://github.com/apps/utterances

The set up process is pretty straight forward...I clicked configure, picked which repo I wanted it to apply to, in this case it was my chadbaldwin.github.io repo. And then let it set up. At this point, it's simply enabled access to the app, it has not been added it to your site yet.

Afterwards it directed me to a page that helps generate the setup script you need (this is the page in case you don't get redirected https://utteranc.es/)

You fill out their form, and at the bottom, you can copy the script that looks something like this:

  <script src="https://utteranc.es/client.js"
          repo="chadbaldwin/chadbaldwin.github.io"
          issue-term="og:title"
          theme="github-light"
          crossorigin="anonymous"
          async>
  </script>

Except in your case, you would use jessieupp/jessieupp.github.io

Then you take that configuration and plop it at the bottom of your post.html layout file here: jessieupp.github.io/_layouts/post.html

Now as soon as someone leaves a comment, it will automatically create a github issue on your behalf, and add that persons comment, and it will now show up on your post. Et voilà!

I may actually modify the blog bootstrap used in this post to add that configuration, but disabled so future readers can simply turn it on with a switch in the _config.yml file.

Hope this helps and happy blogging!

XenocodeRCE commented 2 years ago

@chadbaldwin do you mind telling us how to add other language for syntax highlighting ?

I tried to do so, for c# :

navigate to js/highlightjs/languages/ create csharp.min.js fill in with :

hljs.registerLanguage("csharp",(()=>{"use strict";return t=>({
name:"csharp",aliases:["csharp", "cs"],disableAutodetect:!0})})());

but it doesnt seems to work, im sure im missing something :)

jessieupp commented 2 years ago

Thank you very much for sharing, Chad!! I look forward to testing it out.

On Sun, Aug 15, 2021 at 9:05 AM Sam Harwood @.***> wrote:

@chadbaldwin https://github.com/chadbaldwin do you mind telling us how to add other language for syntax highlighting ?

I tried to do so, for c# :

navigate to js/highlightjs/languages/ create csharp.min.js fill in with :

hljs.registerLanguage("csharp",(()=>{"use strict";return t=>({ name:"csharp",aliases:["csharp", "cs"],disableAutodetect:!0})})());

but it doesnt seems to work, im sure im missing something :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/chadbaldwin/chadbaldwin.github.io/issues/11#issuecomment-899071925, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUHSXOLAPITTODIRBHX57NLT47QTJANCNFSM4ZG6HGUQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

--

Jessie Upp Cell: 206.841.9917​

AndrewVong commented 2 years ago

Thanks so much! Do you know how I can add this blog as a page to an existing site I've already made?

XenocodeRCE commented 2 years ago

So I come back to answer my own question :

Github pages has built-in syntax highlighting, if one no need tsql specific stuff, one can edit /_includes/head.html file and remove any ref to highlights.js, like so :


<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  {%- seo -%}
  <link rel="stylesheet" href="{{ "/assets/main.css" | relative_url }}">
  {%- feed_meta -%}
  {%- if jekyll.environment == 'production' and site.google_analytics -%}
    {%- include google-analytics.html -%}
  {%- endif -%}
</head>

Take care of you everyone

chadbaldwin commented 2 years ago

@XenocodeRCE yup! I was drafting up a response as I saw your comment pop up.

Just an FYI, you still need to fix your _config.yml file as well and remove this:

kramdown:
  syntax_highlighter_opts:
    disable: true

Your other options are to convert it to use the CDN hosted version of highlight.js, or add the csharp language file if for some reason you want to keep using highlight.js.

chadbaldwin commented 2 years ago

Thanks so much! Do you know how I can add this blog as a page to an existing site I've already made?

@AndrewVong , I'm not sure. I'm not too familiar with that sort of stuff. I think your best option would be to set up this site as a subdomain for your main site? At least then it maintains the same domain. But I'm not sure how to set that up.

TJPBray commented 2 years ago

Is there a simple way to (1) change the background colour template and (2) add a personal photo? I've tried changing 'minima' to other (apparently supported) options, but they don't seem to be recognised.

MariannBea commented 2 years ago

This is great! Thank you. I though it was going to take me hours to set up a blog, but this helped me get my first blog post up in less than an hour.

tororutsu commented 2 years ago

is there a way to customize the css of each individual blogpost?

JohnOCFII commented 2 years ago

Very nice! I followed your instructions last night to set up a blog, and this morning, checking your site again, I see you are automatically switching from dark mode to light mode. Curious if you can point to where that is done.

Also - is there a preferred way to link and display images?

Thanks for the clean, easy to follow instructions!

chadbaldwin commented 2 years ago

@JohnOCFII good news for you, it's very easy to set up. There's a Chrome extension I use called "Dark Reader", this extension will automatically convert all pages to a dark theme. It's pretty smart and works well 99% of the time. You can even customize how it makes it dark by changing settings like brightness, contrast, etc.

Well, the creator of the extension also made it so that you can run it on an entire website by including it as a script.

It allows you to support automatic switching based on system settings. Or you can force dark theme. You can also customize the same settings offered in the extension.

To set it up, this is all you need to do:

Open up /_includes/head.html

And add this snippet:

<!-- dark theme using DarkReader -->
<script src="//unpkg.com/darkreader@4.9.40/darkreader.js"></script>
<script type="text/javascript">
  DarkReader.setFetchMethod(window.fetch); // Fix to remedy CORS errors in chrome console
  //DarkReader.enable();
  DarkReader.auto( {brightness: 100, contrast: 90, sepia: 10} );
</script>

This snippet is set up to enable dark theme based on system settings.

You can see it in use on my site here: https://github.com/chadbaldwin/chadbaldwin.github.io/blob/main/_includes/head.html#L39-L45


As far as displaying images, I'll direct you over to this issue where someone asked me something similar:

https://github.com/chadbaldwin/simple-blog-bootstrap/issues/2

chadbaldwin commented 2 years ago

@rjahrj You should be able to add a <style> section to the top of your blog post for custom styling on a per blog post level.

I've done this in the past, see the code for this post: https://github.com/chadbaldwin/chadbaldwin.github.io/blob/main/_posts/2021-01-15-raiserror-cheatsheet.md?plain=1

JohnOCFII commented 2 years ago

Images and Light and Dark are now working. Thanks again!

It looks like you've got some basic tagging setup in your blog (T-SQL, SSMS, etc.) when seen from the archive page. Can you point me in the direction to set up something similar?

chadbaldwin commented 2 years ago

@JohnOCFII More good news...that's a built in feature for the software that builds the blog used by GitHub. The software is called Jekyll.

The feature is called "front matter", and it's a way of giving Jekyll a bit of extra information about your blog post.

You can find more info about it here: https://jekyllrb.com/docs/front-matter/

Here's an example from one of my recent blog posts:

---
layout: post
title: "Working with secure FTP in PowerShell"
description: "Recently learned a new way to work with secure FTP in PowerShell"
date: 2021-11-01T07:00:00-07:00
tags: PowerShell
---

So basically you just use a set of 3 dashes --- and then put the info in there. So in this case, I'm setting these settings, which are all optional:

If all you want is to tag your post then you can simply do this:

---
tags: PowerShell
---

And the "Blog Archive" page will automatically break them up by Tag. So just stick that bit at the very top of the post, and it should just work 👍

JohnOCFII commented 2 years ago

That was so incredibly easy! Thanks so much, @chadbaldwin!

AngelinesYG commented 2 years ago

Hi. I need a little help. Everything worked great, so thanks for that! But I tried changing the theme, and also the "comment with rss" thing didn't work, so I went to _config.yml and commented it out, then changed my theme. But after doing this, the links for the blogs disappeared. The only thing that shows on the site is the "about me" part. I went back to _config.yml and uncommented the rss, but that didn't fix it. I have no idea what could have happened because I didn't touch anything else

ghost commented 2 years ago

Hello Mr Baldwin, I was wondering how I could change the titles font. Currently my title is "Bleeding Trees", and I personally think it looks slightly out of place. Everything else works wonderfully though, and I am eternally grateful for this easy to use template.

andreamoro-git commented 2 years ago

Thanks so much! Do you know how I can add this blog as a page to an existing site I've already made? @AndrewVong I assume your site is a github site. You can clone this project and then at step 3 name your repository "blog" instead, or whatever you want your page to be named. Then, once your repository is set up, go to settings/pages and under source select main/root and save. Your blog will be available at [yoursite/blog].

Not everything will work, you'll have to modify some of the templates and configuration to make sure the baseurl is [yoursite/blog]. Under _config.yml add the variable baseurl: "/blog". You may have to modify other templates if some links don't work, by adding {{ site.baseurl }} to some links.

here is my solution https://github.com/andreamoro-git/blog

jakefrk commented 2 years ago

Thanks for this. Got it set up but test posts aren't displaying. Was there another step? https://jakefrk.github.io/

andreamoro-git commented 2 years ago

@jakefrk it's strange because your archive is showing the posts https://jakefrk.github.io/archive,

are you using the minima theme? Somehow the home layout is not loading, try to copy this file to _layouts/home.html https://github.com/jekyll/minima/blob/master/_layouts/home.html

sgbaird commented 2 years ago

Any suggestions for implementing tooltips with this template?

skmuiruri commented 2 years ago

Nice template, thanks for sharing. Is there a way of getting rid of the rss links?

andreamoro-git commented 2 years ago

Nice template, thanks for sharing. Is there a way of getting rid of the rss links?

edit the head.html template and remove the relevant row

chadbaldwin commented 2 years ago

@skmuiruri, you can disable it by commenting out the line rss: rss in the _config.yml file. Change the line to #rss: rss, this will remove the link, however, RSS functionality will still be there, it just won't show the link.

As far as I know, there's no simple way to completely disable RSS functionality. It is loaded via a default plugin that GitHub Pages includes. There may be a way to disable it entirely maybe through un-loading the plugin somehow, which I've never done before, or maybe through a setting in the plugin itself:

https://github.com/jekyll/jekyll-feed

chadbaldwin commented 2 years ago

@andreamoro-git RSS settings are not part of the head.html include file. The RSS functionality is a default plugin included by GitHub Pages, and is enabled by default. The link is built into the Minima theme and the only way to remove it is by following my instructions above....or by creating a social.html override file that doesn't include it.

chadbaldwin commented 2 years ago

@sgbaird I don't know of any simple way to add tooltips. You'll probably have to go with a generic HTML/CSS solution online. You can mix HTML and Markdown in the same file, so you can probably find some sample tooltip code online, add the CSS to the css/override.css file, and then add your tooltip <span> tags directly in the post.

fedemolina commented 2 years ago

I create my repo as public and then change to private. When I revert to public there is no blog anymore. Do I have to create the blog again?

fedemolina commented 2 years ago

Sorry it takes 5 minutes and then it came back

chadbaldwin commented 2 years ago

@fedemolina the repo must be public and stay public if you are using a free account on GitHub:

https://docs.github.com/en/pages/getting-started-with-github-pages/about-github-pages#:~:text=private%20repositories%20with%20GitHub%20Pro%2C%20GitHub%20Team%2C%20GitHub%20Enterprise%20Cloud%2C%20and%20GitHub%20Enterprise%20Server

fedemolina commented 2 years ago

@chadbaldwin I was trying to write math formulas in latex language but it was not rendered. Is it possibly to make this theme compatible with it? Thanks in advance

chadbaldwin commented 2 years ago

@fedemolina The markdown renderer used by GitHub Pages/Jekyll does not support latex, so you'll need to use a library that is able to render your latex.

I use MathJax (https://www.mathjax.org/). You just need to add it to your site, and then use the appropriate syntax for embedding rendered latex.

So you would need to add this to your head.html file:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

Then for block rendering, you use it like this:

$$
V = \frac{O-P}{FC}
$$

And for inline rendering you use it like this \\(V = \frac{O-P}{FC}\\)

sgbaird commented 2 years ago

@sgbaird I don't know of any simple way to add tooltips. You'll probably have to go with a generic HTML/CSS solution online. You can mix HTML and Markdown in the same file, so you can probably find some sample tooltip code online, add the CSS to the css/override.css file, and then add your tooltip <span> tags directly in the post.

Thanks for your reply! I had some trouble getting a style recognized after adding it to css/override.css; however, I was able to hack around it by putting the <style> directly in the markdown post (note, this would have to be done for each).

<div class="tooltip">Example tooltip
  <span class="tooltiptext">Tooltip text</span>
</div>

<!-- not sure how to make this available to every md file -->
<style>
/* Tooltip from https://www.w3schools.com/css/css_tooltip.asp */
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  bottom: 150%;
  left: 50%;
  margin-left: -60px;
}

.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: black transparent transparent transparent;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
}
</style>
surfinlie commented 2 years ago

This was very helpful, thanks !!

xiaobaobaolong commented 2 years ago

this is very helpful~ could you help add a step at the beginning of Customization such as ' we can search name.github.io in searching box of github.com, then we can find the _config.yml '

slendermon commented 2 years ago

Is there a way to show the thumbnails below the titles? For the front page?

RiddheshB commented 2 years ago

Thank you for making this. I wouldn't have started if I didn't come across this post.

I notice you don't read comments anymore- but I'll try anyways I have one major issues:

Is there a way to export the same styling I get from my markdown editor (Obsidian)? The line breaks are a big issue. I've to enter two times

Like this (To create one line break) - this breaks the formatting I write in Obsidian.

Is there a way to make the page have line breaks when I make only single enter?

chadbaldwin commented 2 years ago

@RiddheshB I do read them...I just don't have much time to respond to them anymore, at least not for this specific post, it's quite active haha.

As for your question, I don't think I have an answer. Assuming I understand what you're describing...In Github Pages, if you write something like this:

This is a single
sentence with a line break.

The webpage will display it as:

This is a single sentence with a line break.

Whereas in Obsidian, it will display it as:

This is a single
sentence with a line break.

As far as an answer to your question...it sounds to me like Obsidian is working in a non-standard way. As single line breaks are usually ignored, and if you want a line break without a new paragraph, then you would put a double space at the end of your line.

However, it does appear that you can get around this using a modifier, check out this solution on StackOverflow and see if that helps:

https://stackoverflow.com/a/62732579

chadbaldwin commented 2 years ago

@101dumbdumb If you're not familiar with Jekyll/Liquid then I'll probably be speaking gibberish here, but you'll at least have some terms to google if this is a project you want to take on.

I'm sure there is a way, you just need to code it up. The front page uses a loop to list out each of the posts. You could adjust that loop to also check to see if the post has a thumbnail image file in its front matter. If an image path is provided then display it below or next to the title in the list.

It would require knowing a little about Jekyll / Liquid, some HTML and some CSS to get it to work.

chadbaldwin commented 2 years ago

@xiaobaobaolong I'm not sure I understand what you're asking? Are you suggesting to use the search box rather than manually looking at the file list to find _config.yml?

ajleeson commented 2 years ago

Thank you so much for this! Do you know of a way for users to "subscribe" to the blog and receive email notifications when I publish a new post?

chadbaldwin commented 2 years ago

@ajleeson I've tried looking into it in the past...there may be some simple/easy options out there, but I haven't found one.

However, the blog template already includes support for RSS...so anyone that uses RSS to follow blogs will get notified already, and that already works free out of the box.

I recall looking into using mailchimp a while back, but I don't think I got very far with it, but that may be a good option to look into.

I've personally never worried about it because as long as you set up your site well, it will pop up on google searches (I assume that's how you found this blog post as that's where I think most of the traffic on this post comes from).

I also do quite a bit of work to promote my blog posts whenever I post a new one...So every time I post a new blog post, I share it on multiple Reddit groups, LinkedIn, Twitter and appropriate Slack groups.

Since I'm not trying to build a business or advertise anything, and this blog is purely for my own enjoyment...that has been sufficient for me so far.

RiddheshB commented 2 years ago

@chadbaldwin

Thank you so much for sharing the stack overflow link! That was just what I needed!

I am curious to know. Whenever you write a blog: Do you manually go _posts -> Write a new name using the date format, followed by the name & write in the text editor, every time?

I find this process a bit clunky. Especially for making edits (as I write my post in Obsidian), then copy paste it.

Is there a way to upload & edit posts directly from Obsidian? I imagine that will make writing seamless, especially for non-tech guys like me. I tried watching a few YouTube videos- but they seem to be geared towards using Git as a means for syncing your vault across devices, not creating blog posts

RiddheshB commented 2 years ago

@chadbaldwin

I hope you see this sometime. Do you know how I can set up short urls? Basically get rid of the dates in the webpage Like this https://sive.rs/su The blog above explains the reasons well

chadbaldwin commented 2 years ago

@RiddheshB There's a few ways you could do this in Jekyll. But, I would suggest checking out the "permalinks" feature. This allows you to specify a hardcoded path for the item.

https://jekyllrb.com/docs/permalinks/

So the only change you would make is adding "frontmatter" to the top of your post, and adding a property that says something like this:

---
permalink: /myblogpost
---

...and now that blog posts URL will be https://yourblog.com/myblogpost. It also supports sub-directories, like /recipes/applepie

However, as far as I know, you can only specify one permalink per file. Another downside is that it's hardcoded on each post, so you need to be more careful that you don't accidentally re-use names.

Permalinks will likely be the simplest solution.

You could also probably accomplish this using "collections" but that would be way more work and require a lot of modifications to the blog.


All that said...I personally don't think it's a very big deal. I don't think I've ever looked at someone's blog post and thought about how long the URL is. If I want to save the blog post, then I just bookmark it, and the URL itself isn't something I pay attention to.

Now, if you find yourself regularly sharing specific pages on your site with other people and you're having to do it from memory, then I can understand that, but I've never found myself to be in that situation.

Just remember that permalinks replace the standard URL. So if you ever want to "add" a short URL reference, that will delete the old path and break any links pointing to it.

So you may want to look into other options if you think that will become and issue. But that may be easier dealt with in the future when you actually need it.

easfire commented 2 years ago

it is very simple and useful, thank you!

HsuJoann commented 1 year ago

https://hsujoann.github.io/2022/08/09/move-my-blog-from-paid-server-to-github.html I got this done today. Thank you very much Chad.

heyakshayjain commented 1 year ago

Hi,I want to add Resume,Contact page But it's not working it seeems. link -heyakshayjain.github.io repo -https://github.com/heyakshayjain/heyakshayjain.github.io