Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some more issues #138

Merged
merged 5 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ preview: {{.Preview}}
{{- end}}
type: {{.Type}}
hide: {{.Hide}}
toc: {{.Toc}}
---
`
)
Expand Down Expand Up @@ -112,6 +113,10 @@ func main() {
Name: "hide",
Usage: "Hides the article",
},
&cli.BoolFlag{
Name: "toc",
Usage: "Adds a table of contents to the article",
},
&cli.BoolFlag{
Name: "top",
Usage: "Places the article at the top",
Expand Down Expand Up @@ -202,6 +207,7 @@ func New(c *cli.Context) {
top := "false"
postType := "post"
hide := "false"
toc := "false"
date := time.Now()

// Empty string values
Expand Down Expand Up @@ -245,6 +251,9 @@ func New(c *cli.Context) {
if c.Bool("hide") {
hide = "true"
}
if c.Bool("toc") {
toc = "true"
}
if c.Bool("draft") {
draft = "true"
}
Expand Down Expand Up @@ -299,6 +308,7 @@ func New(c *cli.Context) {
"Top": top,
"Type": postType,
"Hide": hide,
"Toc": toc,
"Preview": preview,
"Cover": cover,
"Tags": tagString,
Expand Down
12 changes: 8 additions & 4 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type ArticleConfig struct {
Top bool
Type string
Hide bool
Toc bool
Image string
Subtitle string
Config map[string]interface{}
Expand Down Expand Up @@ -129,11 +130,14 @@ func renderHookLazyLoadImage(w io.Writer, node ast.Node, entering bool) (ast.Wal
return ast.GoToNext, false
}

func ParseMarkdown(markdown string) template.HTML {
func ParseMarkdown(markdown string, toc bool) template.HTML {
extensions := parser.CommonExtensions | parser.Footnotes
parser := parser.NewWithExtensions(extensions)

htmlFlags := html.CommonFlags
if toc {
htmlFlags |= html.TOC
}
opts := html.RendererOptions{Flags: htmlFlags, RenderNodeHook: renderHookLazyLoadImage}
renderer := html.NewRenderer(opts)

Expand Down Expand Up @@ -226,10 +230,10 @@ func ParseArticleConfig(markdownPath string) (config *ArticleConfig, content str
// Parse preview splited by MORE_SPLIT
previewAry := strings.SplitN(content, MORE_SPLIT, 2)
if len(config.Preview) <= 0 && len(previewAry) > 1 {
config.Preview = ParseMarkdown(previewAry[0])
config.Preview = ParseMarkdown(previewAry[0], false)
content = strings.Replace(content, MORE_SPLIT, "", 1)
} else {
config.Preview = ParseMarkdown(string(config.Preview))
config.Preview = ParseMarkdown(string(config.Preview), false)
}
return config, content
}
Expand All @@ -250,7 +254,7 @@ func ParseArticle(markdownPath string) *Article {
article.Preview = config.Preview
article.Config = config.Config
article.Markdown = content
article.Content = ParseMarkdown(content)
article.Content = ParseMarkdown(content, config.Toc)
if config.Date != "" {
article.Time = ParseDate(config.Date)
article.Date = article.Time.Unix()
Expand Down
33 changes: 24 additions & 9 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,28 @@ func RenderArticles(tpl template.Template, articles Collections) {
for i := range articles {
currentArticle := articles[i].(Article)
var renderArticle = RenderArticle{currentArticle, nil, nil}
if i >= 1 {
article := articles[i-1].(Article)
renderArticle.Prev = &article
}
if i <= articleCount-2 {
article := articles[i+1].(Article)
renderArticle.Next = &article
// Only show next and prev article if it is not hidden
if !renderArticle.Hide {
if i >= 1 {
// Find prev unhidden article
for j := i - 1; j >= 0; j-- {
prevArticle := articles[j].(Article)
if !prevArticle.Hide {
renderArticle.Prev = &prevArticle
break
}
}
}
if i <= articleCount-2 {
// Find next unhidden article
for j := i + 1; j < articleCount; j++ {
nextArticle := articles[j].(Article)
if !nextArticle.Hide {
renderArticle.Next = &nextArticle
break
}
}
}
}
outPath := filepath.Join(publicPath, currentArticle.Link)
wg.Add(1)
Expand Down Expand Up @@ -164,8 +179,8 @@ func RenderArticleList(rootPath string, articles Collections, tagName string) {
"Develop": globalConfig.Develop,
"Page": i + 1,
"Total": page,
"Prev": prev,
"Next": next,
"Prev": template.URL(filepath.ToSlash(prev)),
"Next": template.URL(filepath.ToSlash(next)),
"TagName": tagName,
"TagCount": len(articles),
}
Expand Down
16 changes: 16 additions & 0 deletions template/source/ink-blog-tool-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ InkPaper is a static blog generator developed in Golang. No dependencies, cross

- Open `http://localhost:8000` in your browser to preview

### Features
- YAML format configuration
- Markdown format articles
- No dependencies, cross platform
- Super fast build times
- Continuously improving theme and typography
- Multiple article authors support
- Archive and tag generation
- Real-time preview when saving
- Offline full-text keyword search
- $\LaTeX$ style math formula support (MathJax):

$$
\int_{-\infty}^\infty g(x) dx = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z-g(x)} dz
$$
### Website Configuration
Edit `config.yml`, use this format:

Expand Down Expand Up @@ -70,6 +85,7 @@ tags: #Optional
- Tag2
type: post #Specify type is post or page, Optional
hide: false #Hide article,can be accessed via URL, Optional
toc: false #Show table of contents,Optional

---

Expand Down
6 changes: 6 additions & 0 deletions template/source/ink-blog-tool.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ preview: 纸小墨(InkPaper)是一个GO语言编写的开源静态博客构
- 归档与标签自动生成
- 保存时实时预览页面
- 离线的全文关键字搜索
- $\LaTeX$ 风格的数学公式支持(MathJax):

$$
\int_{-\infty}^\infty g(x) dx = \frac{1}{2\pi i} \oint_{\gamma} \frac{f(z)}{z-g(x)} dz
$$

### 配置网站
编辑`config.yml`,使用如下格式:
Expand Down Expand Up @@ -82,6 +87,7 @@ tags: #可选
- 标签2
type: post #指定类型为文章(post)或页面(page),可选
hide: false #隐藏文章,只可通过链接访问,可选
toc: false #是否显示文章目录,可选

---

Expand Down
4 changes: 4 additions & 0 deletions template/theme/_head.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
};
var root = '{{.Site.Root}}';
</script>

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

{{if .Develop}}
<script type="text/javascript">
var conn, reloadTimer, connectTimer;
Expand Down