This is a creation in Article, where the information may have evolved or changed.
2012-12-23
Build your blog environment with go language and Org-mode
- Design goals
- Operation Flow
- Directory format
- Blog Header meta format
- function implementation
Design goals
Semi-static blog. Try to be self-contain, with no database dependencies. As long as the full basic functionality. Use the meta-information on the head of the blog to classify, tag and so on, the go language background dynamic generation Browse by category.
The static section includes:
- CSS style files
- Templates for various displays
- Most posts are HTML generated by the org file using emacs
The dynamic section includes:
- RSS feeds generated by the Go Language program
- Manage blog posts by category, tag, etc.
- Comments and other functions later considered
Operation Flow
handwritten org-format blog post. The file format has a special header that stores meta information in JSON format. Then using emacs processing, the org file into the HTML import into the Pub/post directory, only the body part is generated.
Go language write background, the Pub/post directory of files combined with TEMPLATE/POST.TPL to generate the full HTML output. Write a blog as long as the Org file, publish is to use Emacs Export HTML to get Pub/post directory
Directory format
The generated blog directory:
Pub├──css│└──styles.css├──img│├──back-footer.png│├──back.png│└──header.jpg├──page│├──about.html│ └──index.html├──post│├──beansdb.html│├──chibi-scheme0.html│ └─chibi-scheme1.html│└──template ├──arch S.tpl ├──categories.tpl ├──index.tpl ├──left.tpl ├──posts.tpl ├──post.tpl ├──right.tpl └──TAGS.TPL
Pub is the root directory of the generated site, where:
- CSS put style file
- The post directory is full of generated HTML files, generated by the Org file with emacs, the input format is body-only, with a special JSON header
- Templates are template files
Directory of source code:
Src└──blog ├──atom │└──atom.go ├──main.go └──post ├──post.go ├──post_test.go └──te St.html
- Atom packet is the structure definition of the atom feed of XML
- Post is the actual Web server
- In main is an empty function, which is actually called the INIT Registration message processing of the post package.
Post directory:
Org
This directory holds the written format of the blog file, which is in. org format. The file header has special meta information including release date, category, tag, etc.
Blog Header meta format
Title stringdate timecategory []stringtags []string
An example is: {Title: ' Hello World ', data:19890-01-07, category:[' life ', ' test '], tags:null}
function implementation
There are several important data to be included:
var all []*postdatavar Categories map[string][]*postdatavar Tags map[string][]*postdata
All of them are blog posts. Categories are all categories, one class as key, and the corresponding value is a blog post of this category. Tags are similar to categories. The home page shows a column category, which is implemented by using the Go template to display all the keys of categories. The corresponding link is this form: Http://my.blog.com/post?category=key
The background will dynamically generate the corresponding article according to the category. The realization of the feed function is that the XML data format of the feed is defined in Atom.go, and the corresponding data is generated by invoking the XML packet marshal of the go language. The main thing is to marshal after all conversions.