gpt4 book ai didi

go - 如何在 Go 中从 Blackfriday 插入/提取正面内容?

转载 作者:行者123 更新时间:2023-12-03 10:01:54 26 4
gpt4 key购买 nike

在 jekyll 中,您将其插入到 Markdown 的顶部并能够将它们插入到您的布局中:

---

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)
}

最佳答案

我用 https://github.com/gernest/front解析 jekyll 文件。效果很好。首先用 front 解析文件,然后将 body 传递给 blackfriday。

关于go - 如何在 Go 中从 Blackfriday 插入/提取正面内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37494831/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com