发文小计
文本与排版印刷
.w-50 占领50%
.left .right 靠左 靠右
{: data-toc-skip=’’ .mt-4 .mb-0 } toc隐藏
jekyll-compose
Naming and Path
Create a new file named YYYY-MM-DD-TITLE.EXTENSION and put it in the _posts of the root directory. Please note that the EXTENSION must be one of md and markdown. If you want to save time of creating files, please consider using the plugin Jekyll-Compose to accomplish this.
在本章节中我将说明如何通过安装jekyll-compose并使用shell方便的管理文章,也就是说,Streamline your writing in Jekyll with some commands.当然安装之后,你也可以通过bundle exec jekyll help自行查看命令。
环境
先在Gemfile中添加依赖,并用bundle安装。
1
gem 'jekyll-compose', group: [:jekyll_plugins]
草稿
这个命令用于生成_drafts文件夹并生成./draft/how-to-post.md草稿。以下三者等价,都是生成新文章在草稿文件目录下。
1
2
3
4
5
6
7
8
bundle exec jekyll draft "how-to-post"
# or by using the compose command with draft specified
bundle exec jekyll compose "My new draft" --draft
# or by using the compose command with the drafts collection specified
bundle exec jekyll compose "My new draft" --collection "drafts"
发布
用shell发布的好处是会自动更新发布时间,表现为在题目前接上日期,以及文章内yaml中添加时间数据。
第一种方式是直接发布,以下三者等价。
1
2
3
4
5
6
7
8
9
10
bundle exec jekyll post "My New Post"
# or specify a custom format for the date attribute in the yaml front matter
bundle exec jekyll post "My New Post" --timestamp-format "%Y-%m-%d %H:%M:%S %z"
# or by using the compose command
bundle exec jekyll compose "My New Post"
# or by using the compose command with the posts collection specified
bundle exec jekyll compose "My New Post" --collection "posts"
或者从草稿中发布。
1
2
3
4
5
6
bundle exec jekyll publish _drafts/my-new-draft.md
# or specify a specific date on which to publish it
bundle exec jekyll publish _drafts/my-new-draft.md --date 2014-01-24
# or specify a custom format for the date attribute in the yaml front matter
bundle exec jekyll publish _drafts/my-new-draft.md --timestamp-format "%Y-%m-%d %H:%M:%S %z"
回溯、改名
你可以将发布的文章退回草稿状态,表现为文章回到./_draft/并因此离开./post/而不可见。
1
bundle exec jekyll unpublish _posts/2014-01-24-my-new-draft.md
compose提供三种对published文章的改名用途:改名、改日期、改为今天。
1
2
3
4
5
6
7
8
bundle exec jekyll rename _posts/2014-01-24-my-new-draft.md "My New Post"
# or specify a specific date
bundle exec jekyll rename _posts/2014-01-24-my-new-post.md "My Old Post" --date "2012-03-04"
# or specify the current date
bundle exec jekyll rename _posts/2012-03-04-my-old-post.md "My New Post" --now
对于draft文章提供简单改名
1
2
3
4
bundle exec jekyll rename _drafts/my-new-draft.md "My Renamed Draft"
# or rename it back
bundle exec jekyll rename _drafts/my-renamed-draft.md "My new draft"
另外
你也可以直接在根目录生成文章,按照_cofig.yml对scope.path: ""的permalink的默认映射规则,你将在/:title/找到他,也就是。
image-Preview image 1200 x 630
Preview Image
If you want to add an image at the top of the post, please provide an image with a resolution of 1200 x 630. Please note that if the image aspect ratio does not meet 1.91 : 1, the image will be scaled and cropped.
{}是Kramdown扩展语法,用于给Markdown元素添加HTML Class。语法组成为:
1
{: .class-name #id-name key="value" }
回到正题,1200 x 630。
vscode-markdown
我从vs扩展(ctrl+shfit+x)下载了Markdown All in One和Markdown Shortcuts用于md编辑和快捷键。
ctrl+M+ctrl+M十分方便。
vscode-自定义复制文件地址
ctrl+,打开设置,并输入markdown.copy- 找到markdown> Copy Files: Destination
输入键值对: **/*.md/assets/2025-05/${fileName},将本月图片都放到2025-05。- 之后更新文件即可。
1
2
3
4
# 通配符(globbing pattern)匹配说明
*.md 只会匹配 project/a.md
*/*.md 只会匹配 docs/b.md(只深入一层)
**/*.md 会匹配 a.md、docs/b.md、docs/topics/c.md,亦即任意层级
相对路径、绝对路径
When writing posts I find those two are exactly the same. Then I got it: it’s relative path and absolute path.
1
2
 # relative
 # absolute