惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fox-IT International blog
Recent Announcements
Recent Announcements
D
Docker
IT之家
IT之家
B
Blog
Jina AI
Jina AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
量子位
C
Check Point Blog
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
博客园 - 司徒正美
李成银的技术随笔
美团技术团队
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
T
Tailwind CSS Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
小众软件
小众软件
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
M
Microsoft Research Blog - Microsoft Research
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog

Feed of liolok

Fix Broken URLs of My Site Containerize Steam with systemd-nspawn Containerize Android Studio with systemd-nspawn Run Desktop App with systemd-nspawn Container Oculus Quest 2 Usage Note Set Environment Variables with pam_env Install Arch Linux on Acer Swift 3 SF313-52 Run Mastodon Server on Arch Linux VPS V2Ray Subscription Parse Manage Dotfiles with Git and Stow Run SS and MTProxy Server on AWS Build Blog with Hexo and GitHub Pages
How to Add Image to Hexo Blog Post
2019-04-16 · via Feed of liolok

cd ~{,/zhs/}

Makrdown Syntax

Adding an image is supposed to be easy in markdown. Syntax is like: ![alt](path "title"), in which:

  • alt is alternate text, provides alternative information for the image if user cannot view it for some reason like slow connection, wrong path or user is using screen reader;
  • path is image file link, most important part;
  • title is tooltip text (optional), appears when cursor is floating over the image.

In this article I will mainly talk about the image file path or link or whatever you name it. But if you want to make a quick choice in different solutions, follow the map below and jump to the section directly.

Quick Choice

Image Hosting Sevice

An image hosting service allows individuals to upload images to an Internet website. The image host will then store the image onto its server, and show the individual different types of code to allow others to view that image.Wikipedia

There are websites providing this type of sevice: You upload an image file, then get the link of it, or even its markdown code directly.

External URL

![An Imgur Image](https://i.imgur.com/ucHPX7L.gif "An Imgur GIF")

An Imgur Image

In addition, you could even find editors or plugins, that will do the uploading work and insert markdown code automatically after you drag&drop or paste the image.

If you need to save the traffic of your blog site, an image hosting service may be a nice choice. However if you’re already using a static site hosting service like GitHub Pages, and don’t have that many posts and images, there is no need to save traffic at all.

Post Asset Folder

First of all, this feature need to be enabled in Hexo site configuration file _config.yml:

post_asset_folder: true

Then the files in source/_posts should look like this:

2019-02-14-Test-Post.md
2019-02-14-Test-Post/
+-- Test-Image-1.webp
+-- Test-Image-2.webp
+-- Subdirectory/
|   +-- Test-Image-3.webp
|   +-- Test-Image-4.webp

You can see that post asset folder is besides the post source file, and has the same name with it.

Relative Link Based on Post Source File

First you need to install plugin hexo-asset-link:

$ npm i --save hexo-asset-link

Then in markdown source file source/_posts/2019-02-14-Test-Post.md, the base-relative links scheme would look like this:

![](2019-02-14-Test-Post/Test-Image-1.webp)
![](./2019-02-14-Test-Post/Test-Image-2.webp)
![](2019-02-14-Test-Post/Subdirectory/Test-Image-3.webp)
![](./2019-02-14-Test-Post/Subdirectory/Test-Image-4.webp)

Relative Link Based on Post Asset Folder

![](Test-Image-1.webp)
![](./Test-Image-2.webp)
![](Subdirectory/Test-Image-3.webp)
![](./Subdirectory/Test-Image-4.webp)

This type of base-relative link would only works on post page, not on home page excerption or editor preview.

Global Asset Folder

For images it could be source/images or source/img or something similar. For example I place my site favison at root folder:

Pay attention to the first slash ‘/’, without it the link would be a base-relative one.

![Site Favicon](/favicon.ico "My Site Favicon")

Site Favicon

This type of root-relative link works in blog site, but basically not in editor preview.

Hexo Tag Plugin Syntax

Here is the official documentation about this solution, I don’t even want to write it down in my own blog. Here are top comments right below the docs:

Top Comments of Tag Syntax