在jekyll中,您将其插入到降价处的顶部,并且可以将它们插入到您的布局中:
---
layout: post
title: Blogging Like a Hacker
---
我需要在Go中使用没有框架或花哨的包来做同样的事情。只是Golang。
import (
"github.com/russross/blackfriday"
"html/template"
"io/ioutil"
"net/http"
)
type webPost struct {
Title string
Author string
Description string
Body template.HTML
}
func handlePost(res http.ResponseWriter, req *http.Request) {
//Read in some markdown from a file
input, _ := ioutil.ReadFile("test.md")
//Render it into HTML
output := blackfriday.MarkdownCommon(input)
//I need the first three parameters to grab the front matter from test.md
post := webPost{"title", "author", "a descritpion", template.HTML(output)}
//Serve to client a template
templates.ExecuteTemplate(res, "Post", post)
}
答案 0 :(得分:0)
我使用 https://github.com/gernest/front 来解析 jekyll 文件。工作得很好。首先用 front
解析文件,然后将 body 传递给 blackfriday。