Build your blog environment with go language and Org-mode

Source: Internet
Author: User
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

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        └──test.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
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 XML package of the go language is called.
Marshal generates the corresponding data. The main thing is to marshal after all conversions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.