学习ox-hugo自定义todo状态的css样式
文章目录
【注意】最后更新于 November 24, 2021,文中内容可能已过时,请谨慎使用。
hugo 开启支持自定义css
在长期使用org管理项目导出hugo博客时,在ox-hugo文档中有设置todo状态的方法。
但是放在hugo效果中无法呈现逾期效果,经过一番查找,需要设在hugo配置文件中设置支持html自身css样式的加载,否则,hugo 会生成 <!-- raw HTML omitted --> html标签,禁止用户自定义样式。
- todo-css 无效果问题解决 - 1 2 3 4- [markup] [markup.goldmark] [markup.goldmark.renderer] unsafe = true- twitter bootstrap - Hugo shortcode ignored saying “raw HTML omitted” - Stack … 
借助org嵌套语法,添加css样式
在ox-hugo文档中介绍css加载的方法,经过一几番测试,在不同节点和宏 #include css 到博客中,都无法达到预期的效果。
- 声明css 样式节点 - 重点:设置 - CUSTOM_ID属性:todo-css- 有了 - CUSTOM_ID值,就可以通过org嵌套语法- #+include,在其他节点嵌套该节点的内容。- 例如:在 - all-posts.org文件中,创建一个- CSS for TODO节点,专门放置css 样式。- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20- ** CSS for TODO :noexport: :PROPERTIES: :CUSTOM_ID: todo-css :END: #+begin_export html <style> .org-todo { font-size: 0.8em; font-weight: 700; } /* *** Org TODO set to TODO state */ .org-todo.todo { color: #e60000; } /* *** Org TODO set to DONE state */ .org-todo.done { color: green; } </style> #+end_export
- 使用 - #+include:嵌套语法,在- project.org文件中嵌套- CSS for TODO中css 样式内容。- 1- #+include: "./all-posts.org::#todo-css" :only-contents t
- org-hugo 导出博客后,查看博客html 效果和源码 - 1- <span class="org-todo done DONE">DONE</span> 人脸识别
ox-hugo.el高级定制
在设置了hugo支持绘制css样式之后,就想让博客支持更多的cancel状态的下的样式,下一个问题是如何扩展ox-hugo支持自定义更多的样式问题。
经过查看ox-hugo 源码,在ox-hugo.el 文件中的方法 org-hugo--todo 可以对状态类型扩展。
下面代码会在导出html 时,对节点添加的css 样式,在第19 行可以看出,目前支持 done , todo 两种样式的设置
|  |  | 
要事第一,制定下一步行动
记录一下折腾笔记,确认要使用的样式,杜绝在小事上浪费精力。
借助hugo配置加载自定义css样式
解决使用 #include: 方式嵌套css 样式,导致文章在主页中显示css 文本。
- 在 - hugodir/static/css/目录中创建todo.css 文件- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16- .org-todo { font-size: 0.8em; font-weight: 700; } /* *** Org TODO set to TODO state */ .org-todo.todo { color: #e60000; } /* *** Org TODO set to DONE state */ .org-todo.done { color: green; } .org-todo.cancel { color: blue; }
- customCSS参数加载自定义的css 样式- 1- customCSS = ["todo.css"]
- 效果 - 1- <link rel="stylesheet" href="/css/todo.css">
文章作者 iTBoyer
上次更新 2021-11-24