emacs 替换模式_如何使用Emacs Org模式撰写博客
emacs 替换模式
我在博客的头几年使用WordPress,但我确实想完全使用GNU Emacs来发布它。 我尝试了Org2Blog ,但仍然缺少某些东西,感觉不满意。 我尝试创建一个网站来发布Emacs配置,我首先使用Django ,然后使用Jekyll来命名为Haqiba (我知道这是一个不寻常的名称)。 Jekyll很酷,可以提供对内容和发布的更多控制,但是我仍然不能直接从Emacs博客,并且仍然缺少Org模式 。 尽管我尝试使用jekyll-org向Jekyll添加Org模式支持,但该框架似乎有些陌生。
组织发布 。 我在搜索中偶然发现了组织发布,但起初,我认为对于博客来说太复杂了。 但是我尝试了一下,从那时起一直很高兴。
许多网站,包括此列表中的网站,都使用org-publish。 例如,伯恩特·汉森(Bernt Hansen)的组织模式-用纯文本组织您的生活,不仅使用组织发布来发布内容,而且还提供了许多信息以使您对组织模式有更深入的了解。
组织发布的优势
组织发布包括以下功能:
- 良好地控制配置,CSS,媒体和发布
- 组织模式格式化支持
- 静态文件生成
- 使用GitLab和GitHub CI / CD轻松部署
- 如果您希望将文件复制到远程服务器而不是使用GitLab页面或GitHub页面,则可以通过Apache / Nginx /文件服务器轻松托管
- 版本控制
- GNU Emacs中的所有内容。 好极了!
基本设定
组织发布指南提供了入门的基本模板。 我鼓励您阅读本教程,因为本教程中的基本设置足以使您对org-publish有一个简短的了解。 首先在myblog /项目目录内的publish.el文件中配置一个名为org-publish-project-alist的变量。 将以下内容放在publish.el中 :
(require 'ox-publish)
(setq org-publish-project-alist
'(("posts"
:base-directory "posts/"
:base-extension "org"
:publishing-directory "public/"
:recursive t
:publishing-function org-html-publish-to-html
:auto-sitemap t)
("all" :components ("posts"))))
第一行是导入语句。 变量org-publish-project-alist具有发布项目列表,以控制发布行为。 第一个元素posts ,是完成博客文章特定的所有配置的地方。 例如,属性:base-directory配置用于保存所有帖子(组织格式)的目录。 同样, :publishing-directory将目录配置为保存由Org文件生成HTML文件。 将:recursive属性设置为t将从posts /及其子目录内的所有Org文件递归生成HTML。 :auto-sitemap属性使用您的帖子列表生成sitemap.html (您将在下面进行调整)。 最后, :publishing-function org-html-publish-to-html将所有的org文件转换为HTML。 虽然您也可以定义自己的函数,但出于本演示的目的,请使用ox-publish提供的内置函数。
您需要一些测试用的帖子,因此创建一个名为posts / post_one.org的文件,并包含一些带有一些内容的基本标题。 使用Cc Ce#default和Cc Ce#html分别包含默认模板和HTML模板。
您的文件应如下所示:
#+title: Post One
#+date: <2020-02-12 Wed>
#+author: John Doe
#+email: john.doe@example.com
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
设置几乎完成。 您可以使用Mx org-publish-all生成HTML并使用make处理发布。 以下是Makefile的内容:
# Makefile for myblog
.PHONY: all publish publish_no_init
all: publish
publish: publish.el
@echo "Publishing... with current Emacs configurations."
emacs --batch --load publish.el --funcall org-publish-all
publish_no_init: publish.el
@echo "Publishing... with --no-init."
emacs --batch --no-init --load publish.el --funcall org-publish-all
clean:
@echo "Cleaning up.."
@rm -rvf *.elc
@rm -rvf public
@rm -rvf ~/.org-timestamps/*
这是项目的当前布局:
myblog
├── Makefile
├── posts
│ └── post_one.org
└── publish.el
执行make将在public /目录中生成sitemap.html和post_one.html :
myblog
├── Makefile
├── posts
│ ├── post_one.org
│ └── sitemap.org
├── public
│ ├── post_one.html
│ └── sitemap.html
└── publish.el
将CSS添加到您的帖子中
您可以增强publish.el文件,使其包含CSS或图像之类的元素。 要尝试此操作,请为CSS添加一个部分或项目。 修改后的publish.el应该如下所示:
(require 'ox-publish)
(setq org-publish-project-alist
'(("posts"
:base-directory "posts/"
:base-extension "org"
:publishing-directory "public/"
:recursive t
:publishing-function org-html-publish-to-html
:auto-sitemap t)
("css"
:base-directory "css/"
:base-extension "css"
:publishing-directory "public/css"
:publishing-function org-publish-attachment
:recursive t)
("all" :components ("posts" "css"))))
创建一个名为css /的新目录,并将代码从site.css复制到其中。 现在,创建第二篇文章来测试CSS。
#+title: Post Two
#+date: <2020-02-12 Wed>
#+author: John Doe
#+email: john.doe@example.com
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../css/site.css" />
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
在此示例中,使用#+ HTML_HEAD:选项包含CSS。 组织发布教程建议使用#+ STYLE:选项包括样式表,但这对我不起作用。 相反,我使用了#+ HTML_HEAD:,这是Org模式手册中建议的CSS支持 。
这是显示css /目录的布局:
myblog
├── css
│ └── site.css
├── Makefile
├── posts
│ ├── post_one.org
│ └── post_two.org
└── publish.el
必须在每个帖子中包含#+ HTML_HEAD:很快就会变得乏味。 网站中也有多个样式表。 要解决此问题,请使用#+ SETUPFILE:选项:
#+title: Post Two
#+date: <2020-02-12 Wed>
#+author: John Doe
#+email: john.doe@example.com
#+SETUPFILE: ../org-template/style.org
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
org-template / style.org文件包含样式表的路径:
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../css/site.css" />
以下是最终布局:
myblog
├── css
│ └── site.css
├── Makefile
├── org-template
│ └── style.org
├── posts
│ ├── post_one.org
│ └── post_two.org
└── publish.el
调整站点地图
最终配置将生成index.html文件而不是sitemap.html文件。 重命名标题并在网站上配置作者和电子邮件。 下面是完成的publish.el文件:
(require 'ox-publish)
(setq org-publish-project-alist
'(("posts"
:base-directory "posts/"
:base-extension "org"
:publishing-directory "public/"
:recursive t
:publishing-function org-html-publish-to-html
:auto-sitemap t
:sitemap-title "Blog Index"
:sitemap-filename "index.org"
:sitemap-style list
:author "John Doe"
:email "john.doe@example.com"
:with-creator t)
("css"
:base-directory "css/"
:base-extension "css"
:publishing-directory "public/css"
:publishing-function org-publish-attachment
:recursive t)
("all" :components ("posts" "css"))))
如果您在设置项目时遇到困难,可以在我的GitLab页面上查看整个项目。
使用现有的组织发布设置
从头开始创建具有org-publish的博客可能变得很乏味。 为了使它更容易,您可以使用我的存储库作为基本模板来使用org-publish发布自己的博客。
要使用它,请克隆blog_template分支:
git clone https: // gitlab.com / psachin / psachin.gitlab.io -b blog_template --single-branch myblog
使用make将组织页面导出为HTML。 public /目录将包含托管所需的所有文件:
cd myblog
make
在posts / template.org中有一个示例博客文章供参考。 您可以使用.gitlab-ci.yaml文件将public /的内容发布为GitLab页面。
奖金小费1
执行make命令后, public /目录将具有托管静态站点所需的所有文件。 您所要做的就是将网络服务器配置为提供此目录,或者您可以使用Python的内置http.server模块在本地呈现博客。
在Python 3.6中,使用:
cd myblog / public
python -m http.server
如果您拥有Python 3.7,则可以使用以下命令提供public /服务:
cd myblog
python -m http.server --directory =public
在网络浏览器中打开http:// localhost:8000 /以查看您的网站。
奖金小费2
这是我最喜欢的提示。 如果没有时间处理新博客文章的想法时,我会使用Org捕获模板快速创建草稿。 我使用下面的模板定义通过键入Cc cp打开缓冲区窗口。 完成后,我输入Cc Cc保存草稿。
将此Elisp片段复制到现有的Emacs配置文件中(但要确保更改了文件路径):
(defun create-blog-post ()
"Create an org file in ~/source/myblog/posts."
(interactive)
(let ((name (read-string "Filename: ")))
(expand-file-name (format "%s.org" name) "~/source/myblog/posts/")))
(setq org-capture-templates
'(("p" "Post" plain
(file create-blog-post)
(file "~/.emacs.d/org-templates/post.orgcaptmpl"))))
这是〜/ .emacs.d / org-templates / post.orgcaptmpl的内容 :
#+title: %^{Name}
#+date: <%<%Y-%m-%d>>
#+keywords: draft
#+setupfile: ../org-templates/post.org
%?
#+INCLUDE: "../disquss.inc"
有关Org捕获模板的更详尽说明,您可以观看我的视频演示 。
您是否曾经使用过组织模式来发布网站或博客,或者打算这样做? 让我们知道您在评论中的经验。
翻译自: https://opensource.com/article/20/3/blog-emacs
emacs 替换模式
emacs 替换模式_如何使用Emacs Org模式撰写博客相关推荐
- ubuntu 安装Pangolin 过程_余辉亮的学习笔记的博客-CSDN博客_pangolin安装
ubuntu 安装Pangolin 过程_余辉亮的学习笔记的博客-CSDN博客_pangolin安装
- python脚本监控网站状态 - 赵海华_运维之路 - 51CTO技术博客
python脚本监控网站状态 - 赵海华_运维之路 - 51CTO技术博客 python脚本监控网站状态 2013-01-09 09:21:02 标签:监控 python 原创作品,允许转载,转载时请 ...
- 酷绅下午茶:那些年 那些事(一)_型牌男装在线定做 - 阿里巴巴博客
酷绅下午茶:那些年 那些事(一)_型牌男装在线定做 - 阿里巴巴博客 酷绅下午茶:那些年 那些事(一)_型牌男装在线定做 - 阿里巴巴博客 酷绅下午茶:那些年 那些事(一) (2010/01/08 1 ...
- 一天学一个模式_第一天:策略模式
概念: 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化. (原文:The Strategy Pattern defi ...
- 抽象工厂模式_设计模式系列—抽象工厂模式
前言 23种设计模式速记 单例(singleton)模式 工厂方法(factory method)模式 23种设计模式快速记忆的请看上面第一篇,前面说完了工厂方法模式,我们发现工厂方法模式存在一个严重 ...
- 构建器模式_我喜欢构建器模式的三个原因
构建器模式 有三种方法可以用Java编程语言创建新对象: 伸缩构造函数(反)模式 Javabeans模式 建造者模式 与其他两种方法相比,我更喜欢使用构建器模式. 为什么? Joshua Bloch描 ...
- java抽象类和模板模式_测试抽象类和模板方法模式
java抽象类和模板模式 摘自Wikipedia,"模板方法定义了算法的程序框架. 子类可以覆盖一个或多个算法步骤,以允许不同的行为,同时确保仍然遵循总体算法." 通常,此模式由两 ...
- hexo博客添加暗色模式_我如何将暗模式添加到我的网站
hexo博客添加暗色模式 I recently redesigned my website. Here are 2 pictures of how it looked, for reference: ...
- 创建型模式、结构型模式和行为型模式_设计模式之创建型模式
设计模式GOF23(Group of Four) 设计模式可分为三种类型: 创建型模式:单例模式,工厂模式,抽象工厂模式,建造者模式,原型模式. 结构型模式:适配器模式,桥接模式,装饰模式,组合模式, ...
最新文章
- 我的人工智能机器人的游戏
- 1.Hadoop初步环境搭建(ssh无密码通信)
- CentOS7 redis-3.2.8 从单机到主从再到集群配置
- Jenkins+Maven+SVN快速搭建持续集成环境
- ODataModel.submitBatch by default Asynchronous
- 返回值被忽略_《Jenkins Tips 001》 忽略 Shell 步骤中的故障
- python3解释器执行long(10)的结果为_Python3解释器执行'AB2C3D'.lower().title()的结果是( )。...
- Halcon:区域特征:select_shape(Regions : SelectedRegions : Features, Operation, Min, Max : )
- vba执行linux命令,从VBA中的shell命令捕获输出值?
- JAVA-重写equalse规范、技巧
- 第二届(2009年)中国信息技术应用学术研讨会征文延期通知
- RabbitMQ 安装与简单使用
- carry函数在C语言中用法,CArry的使用完整版.doc
- Amoeba 实现Mysql的读写分离
- GDB简单调试linux内核与模块的方法
- maven打包,java内存竟然要设置16G(-Xmx16384m)
- springmvc源码-参数解析
- virtualbox 给linux共享文件夹
- 贝叶斯公式的最通俗解释
- 计算机技术检索,计算机检索常用技术.ppt