obsidian是一款好用的markdown编辑器, 用来记笔记还是不错的。 并且支持插件系统,可以通过模板来生成博客的frontmatter, 省去了hexo new的操作 所以准备配置一下用obsidian来写博客。

相关文章:
静态博客生成工具hexo
使用typora更好更快地写hugo博客
使用vscode来写hugo博客并处理图片插入问题

打开仓库

首先使用obsidian打开source/_posts目录, 然后会生成一些配置文件。进入_posts目录

创建.gitignore将一些临时文件排除掉。

1
.obsidian/workspace.json

配置模板

自带的模板插件功能太单一了, 我们关闭安全模式, 安装第三方插件Templater

创建Templates目录,修改配置指定Template的目录。修改配置项Template folder locationTemplates

然后再此目录下创建Front-matter.md文件,此文件用作hexo的frontmatter模板。

1
2
3
4
5
6
7
8
9
---
title: <% tp.file.title %>
categories:
- <% tp.file.folder(relative=true) %>
tags:
- ''
abbrlink: <% tp.user.get_guid() %>
date: <% tp.date.now(format="YYYY-MM-DD HH:mm:ss") %>
---

其中:

模板 作用
tp.file.title 获取到的就是文件名
tp.file.folder(relative=true) 是获取文件所在的相对路径,就是所在目录名字
tp.user.get_url() 是自定义方法,脚本后面展示,用于自动生成博客的url
tp.date.now(format=”YYYY-MM-DD HH:mm:ss”) 以指定格式格式化时间

详细的变量使用请查看Templater官方文档https://silentvoid13.github.io/Templater/

自定义脚本

创建目录Scripts, 然后在设置里配置Script files folder locationScripts

获取GUID脚本 Scripts/get_url.js

1
2
3
4
5
6
7
function generateTimestampUrl() {
var timestamp = new Date().getTime();
var url = timestamp.toString(36)
return url;
}

module.exports = generateTimestampUrl;

然后每次创建新markdown文件的时候,只需要点击templater按钮, 然后就会自动生成我们需要的frontmatter, 就不用 hexo new 了

渲染时排除这些目录

在主配置文件中 _config.yml

1
2
3
4
5
6
skip_render: 
# 这里排除的是obsidian编辑器需要的文件
- '_posts/.obsidian/*'
- '_posts/Scripts/*'
- '_posts/Templates/*'
- '**/README.md'

使用git插件进行同步

安装Obsidian GIT 插件
按下快捷键CTRL + P 选择 commit all changes , 然后选择 push 即可发布。

使用image-auto-upload-plugin来处理图片

默认情况下obsidian插入图片会插入到附件文件夹, 安装此插件会自动调用picgo或者piclist来进行文件上传并复制markdown语法到文件中.