I was priviously using jekyll TeXt theme, but the code block shows too small to watch code. Also, I don’t really understand the coding language jekyll is using, so I decide to switch to a more familier javascript framework, hexo.
What is Hexo?
Hexo is a website generator to generate website based on Markdown file, and it is highly customizable.
Install Hexo
Preriquisite: Git and node.js.
Install Hexo CLI
1
npm install -g hexo-cli
and, we can execute Hexo commands in this way:
1
npx hexo <command>
Install Starter Package & Dependencies
1 2 3
npx hexo init blog cd blog npm install
Server
Run these commands, and you will see a starter website is generated by Hexo.
1 2
npx hexo g npx hexo s
Writing
In sourse/__post folder, we already have a hello-world.md post that is from Hexo starter package. Basically, we can imitate that first.
You can search for theme you like on This Site or Github, but in hexo, I will generally recommand next. It’s not only because it’s highly customizable, but for its already built nice plugins.
Deploy
Use
1
npx hexo g
It will generate html file that you might want to deploy to github in pulic directory, and you can use Github Pages to handle that.
select all font styles that you might want to have.
find its’ url ex:https://fonts.googleapis.com/css2?family=Caveat:wght@400;500;600;700&display=swap, which will be inTo embed a font, copy the code into the <head> of your html/<link>
open it in the browser and convert it to example.css
make a directory “fonts” ex:mkdir fonts
make a main.py in same directory.
paste the automate python code in it.
comfirm that this directory has three object:
main.py
empty directory fonts
example.css
run the python code python main.py
embed example.css in your html file
main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
import requests import re
withopen("example.css", "r") as f: text = f.read() urls = re.findall(r'(https?://[^\)]+)', text)
for url in urls: filename = url.split("/")[-1] r = requests.get(url) withopen("./fonts/" + filename, "wb") as f: f.write(r.content) text = text.replace(url, "'./fonts/" + filename +"'")
withopen("example.css", "w") as f: f.write(text)
credit: duydb, Wytamma Wirth and me who modified it to the better