目录
1 FAQ [3/8]
([37%]
)
1.1 INBOX 如何设置style文件链接使之在所有文件中可以公用?
1.2 DONE 如何设置文内引用链接保持在文件路径变化时文件内容不变?
- State "DONE" from "WAIT/FORWARD"
- State "WAIT/FORWARD" from "NEXT"
等待整理 - State "NEXT" from
1.2.1 链接引用文件存放地
文章引用的文件,存放在jekyll中data目录的,名为对应文章所在文件扩展名替换为 .files
的目录中。
假设引用的是一个图片文件, 引用的文章文件名称是 2015-12-17-testexport.org
, 导出到jekyll系统中的名称是 2015-12-17-testexport.html
, 那么其文章所有被引用的文件都存放在 data/2015-12-17-testexport.files
。
1.2.2 org文件中引用链接到jekyll导出文件链接的转换
org文件中的引用链接,在导出到jekyll的html需要进行转换才能正确显示,转换方式如下
1.2.2.1 org文章使用链接的方式
org文章中引用本地外部文件和普通orgmode语法一样,如下
[[file:~/mygitrepo/quietheart/mydoc/prepub/orgmode/data/2015-12-17-testexport.files/2015-12-17-editor_study_line.jpg][image file]]
1.2.2.2 导出的html链接
导出结果到jekyll对应的html文件后,对应链接变成
<a href="file:///home/miracle/mygitrepo/quietheart/mydoc/prepub/orgmode/data/2015-12-17-testexport.files/2015-12-17-editor_study_line.jpg">image file</a>
1.2.2.3 对导出的html链接进行转换
这样的结果在jekyll中是无法直接正确显示链接的,需要在导出为html之后,再对相应html文件中相应的链接处进行处理,处理成jekyll可以显示的方式,这里为:
<a href="/data/2015-12-17-testexport.files/2015-12-17-editor_study_line.jpg">image file</a>
处理成功的效果:
1.2.3 转换实现
这里实现上述转换的方法是定义一个替换链接的函数,把它做为hook添加到 org-publish-after-publishing-hook
中。
大致如下:
(defun my-update-jekyll-html-link (htmlfile) ;;replace the local file link to site relative link in jekyll. ;;open (setq htmlbuffer (find-file-existing htmlfile)) ;;search (goto-char (point-min)) ;;TODO the xxx.files, xxx is better to be replaced by the html file name. (while (re-search-forward "\\(<a href=.*?\\)\\(file:.*?quietheart/mydoc/prepub/jekyll\\)\\(/data/[0-9]\\{4\\}-[0-1][0-9]-[0-3][0-9]-.*?\.files\\)" nil t) (replace-match "\\1\\3" nil nil)) ;;save and close (save-buffer) (kill-buffer htmlbuffer))) (defun my_after_pub_html_hook (orgfile htmlfile) (my-update-jekyll-html-link htmlfile) ) (add-hook 'org-publish-after-publishing-hook 'my_after_pub_html_hook)))
1.3 DONE 如何设置图片链接在文件路径变化时保持不变?
- State "DONE" from "NEXT"
- State "NEXT" from
类似文件链接的转换, 如何设置文内引用链接保持在文件路径变化时文件内容不变?
关键添加如下:
;;image reference link convert. ;;TODO the xxx.files, xxx is better to be replaced by the html file name. (while (re-search-forward "\\(<img .*?src=.*?\\)\\(file:.*?quietheart/mydoc/prepub/orgmode\\)\\(/data/[0-9]\\{4\\}-[0-1][0-9]-[0-3][0-9]-.*?\.files\\)" nil t) (replace-match "\\1\\3" nil nil))
效果:
1.4 NEXT 如何设置文件中的签名信息?
- State "NEXT" from
1.5 DONE 如何设置文件中jekyll文章的引用位置?
- State "DONE" from "NEXT"
- State "NEXT" from
类似上面导出文件链接的转换, 如何设置文内引用链接保持在文件路径变化时文件内容不变?
关键如下:
(while (re-search-forward "\\(<a href=.*?\\)\\(file:.*?quietheart/mydoc/prepub/orgmode\\)\\(/.*?\\)\\(_posts/[0-9]\\{4\\}-[0-1][0-9]-[0-3][0-9]-\\)\\(.*?\.html\\)" nil t) (replace-match "\\1\\3\\5" nil nil))
效果 gtd method
1.6 NEXT 如何为每次更新文章追加设置记录时间戳?
- State "NEXT" from
1.7 NEXT 如何放置引用文章链接在文章路径改变时的失效情况发生?
- State "NEXT" from
1.8 NEXT 如何为本地orgmode导出文件设置导出引用链接?
- State "NEXT" from
这个和发布不同,日常orgmode管理之时,一般都会将相关文章放到一个目录中,引用的文件也属于该目录的子目录。这种情况下,使用 elisp:
链接的方式来自定义链接的引用。
;; custom link function for export. (defun my-link-org-file (file_path) (setq org-file-prefix org-directory) (find-file (concat org-file-prefix file_path))) (defun my-link-org-img (imgfile_path) (setq org-file-prefix org-directory) (find-file (concat org-file-prefix imgfile_path)))
[[elisp:(my-link-org-file%20"data/image/2010-04-02-editor_study_line.jpg")][normalfile]] [[elisp:(my-link-org-img%20"data/image/2010-04-02-editor_study_line.jpg")][imagefile]]
<a href="(my-link-org-file%20"data/image/2010-04-02-editor_study_line.jpg")">normalfile</a> <a href="(my-link-org-img%20"data/image/2010-04-02-editor_study_line.jpg")">imagefile</a>