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

Update build tool's and theme's dependencies #136

Merged
merged 2 commits into from
Jan 30, 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
19 changes: 9 additions & 10 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"io/ioutil"
"io"
"mime/multipart"
"net/http"
"os"
Expand All @@ -14,7 +14,6 @@ import (

"github.com/InkProject/ink.go"
"github.com/facebookgo/symwalk"
// "fmt"
)

type NewArticle struct {
Expand Down Expand Up @@ -91,7 +90,7 @@ func ApiGetArticle(ctx *ink.Context) {
return
}
filePath := article.Path
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
Expand Down Expand Up @@ -124,7 +123,7 @@ func ApiCreateArticle(ctx *ink.Context) {
return
}
filePath := filepath.Join(sourcePath, article.Name+".md")
err = ioutil.WriteFile(filePath, []byte(article.Content), 0644)
err = os.WriteFile(filePath, []byte(article.Content), 0644)
if err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
Expand All @@ -150,7 +149,7 @@ func ApiSaveArticle(ctx *ink.Context) {
}
// Write
path := cacheArticle.Path
err = ioutil.WriteFile(path, []byte(article.Content), 0644)
err = os.WriteFile(path, []byte(article.Content), 0644)
if err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
Expand All @@ -164,7 +163,7 @@ func getFormFile(ctx *ink.Context, field string) (data []byte, handler *multipar
replyJSON(ctx, http.StatusBadRequest, err.Error())
return nil, handler, err
}
data, err = ioutil.ReadAll(file)
data, err = io.ReadAll(file)
if err != nil {
replyJSON(ctx, http.StatusBadRequest, err.Error())
return data, handler, err
Expand All @@ -191,7 +190,7 @@ func ApiUploadFile(ctx *ink.Context) {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
}
if err = ioutil.WriteFile(filepath.Join(fileDirPath, handler.Filename), fileData, 0777); err != nil {
if err = os.WriteFile(filepath.Join(fileDirPath, handler.Filename), fileData, 0777); err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
}
Expand All @@ -202,7 +201,7 @@ func ApiUploadFile(ctx *ink.Context) {

func ApiGetConfig(ctx *ink.Context) {
filePath := filepath.Join(rootPath, "config.yml")
data, err := ioutil.ReadFile(filePath)
data, err := os.ReadFile(filePath)
if err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
Expand All @@ -211,13 +210,13 @@ func ApiGetConfig(ctx *ink.Context) {
}

func ApiSaveConfig(ctx *ink.Context) {
content, err := ioutil.ReadAll(ctx.Req.Body)
content, err := io.ReadAll(ctx.Req.Body)
if err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
}
filePath := filepath.Join(rootPath, "config.yml")
err = ioutil.WriteFile(filePath, []byte(content), 0644)
err = os.WriteFile(filePath, []byte(content), 0644)
if err != nil {
replyJSON(ctx, http.StatusInternalServerError, err.Error())
return
Expand Down
3 changes: 1 addition & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"
"html/template"
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -89,7 +88,7 @@ func Build() {
fileExt := strings.ToLower(filepath.Ext(path))
baseName := strings.ToLower(filepath.Base(path))
if fileExt == ".html" && strings.HasPrefix(baseName, "_") {
html, err := ioutil.ReadFile(path)
html, err := os.ReadFile(path)
if err != nil {
Fatal(err.Error())
}
Expand Down
12 changes: 5 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@ module github.com/InkProject/ink

go 1.18

replace github.com/InkProject/blackfriday v0.0.0-20181012080017-b70c36859218 => github.com/russross/blackfriday v1.6.0

require (
github.com/InkProject/blackfriday v0.0.0-20181012080017-b70c36859218
github.com/InkProject/ink.go v0.0.0-20160120061933-86de6d066e8d
github.com/facebookgo/symwalk v0.0.0-20150726040526-42004b9f3222
github.com/fsnotify/fsnotify v1.4.9
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c
github.com/gorilla/feeds v1.1.1
github.com/gorilla/websocket v1.4.2
github.com/urfave/cli/v2 v2.1.1
github.com/urfave/cli/v2 v2.24.2
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/facebookgo/testname v0.0.0-20150612200628-5443337c3a12 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.1.0 // indirect
)
24 changes: 10 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/InkProject/ink.go v0.0.0-20160120061933-86de6d066e8d h1:cKKHWaSZqckOTguui9bShV83raKxQKpTB9X4M7WbeaY=
github.com/InkProject/ink.go v0.0.0-20160120061933-86de6d066e8d/go.mod h1:sGm8pED0mDi7pXIgjvCf7/m7LMmLSWpz3bhtB8KoKL8=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
Expand All @@ -17,6 +16,8 @@ github.com/facebookgo/testname v0.0.0-20150612200628-5443337c3a12 h1:pKeuUgeuL6j
github.com/facebookgo/testname v0.0.0-20150612200628-5443337c3a12/go.mod h1:IYed2VYeQcs7JTN6KiVXjaz6Rv/Qz092Wjc6o5bCJ9I=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c h1:iyaGYbCmcYK0Ja9a3OUa2Fo+EaN0cbLu0eKpBwPFzc8=
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
Expand All @@ -26,21 +27,16 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.24.2 h1:q1VA+ofZ8SWfEKB9xXHUD4QZaeI9e+ItEqSbfH2JBXk=
github.com/urfave/cli/v2 v2.24.2/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"html/template"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -373,7 +372,7 @@ func Convert(c *cli.Context) {
fileExt := strings.ToLower(filepath.Ext(path))
if fileExt == ".md" || fileExt == ".html" {
// Read data from file
data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
fileName := filepath.Base(path)
Log("Converting " + fileName)
if err != nil {
Expand Down Expand Up @@ -431,7 +430,7 @@ func Convert(c *cli.Context) {
if fileExt != ".md" {
targetName = targetName + ".md"
}
ioutil.WriteFile(filepath.Join(rootPath, targetName), []byte(markdownStr), 0644)
os.WriteFile(filepath.Join(rootPath, targetName), []byte(markdownStr), 0644)
count++
}
return nil
Expand Down
56 changes: 46 additions & 10 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package main

import (
"html/template"
"io/ioutil"
"io"
"os"
"path/filepath"
"strings"
"time"

"gopkg.in/yaml.v2"

"github.com/InkProject/blackfriday"
gomk "github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/ast"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
)

type SiteConfig struct {
Expand Down Expand Up @@ -97,9 +101,43 @@ const (
MORE_SPLIT = "<!--more-->"
)

// Modify the rendering of the image node to use jQuery-unveil to lazy load images.
//
// Note: This is a hacky way to do this, but it works for now.
// LazyLoadImages in markdown.html.Flags should not be used with this hook, and
// adding the absolute path prefix to the image destination (which is what the original parser does)
// is not implemented yet.
func renderHookLazyLoadImage(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
// Skip all nodes that are not Image nodes
if _, ok := node.(*ast.Image); !ok {
return ast.GoToNext, false
}
img := node.(*ast.Image)
if entering {
if img.Attribute == nil {
img.Attribute = &ast.Attribute{}
}
if img.Attrs == nil {
img.Attrs = make(map[string][]byte)
}
img.Attrs["data-src"] = img.Destination
img.Destination = []byte("data:image/gif;base64,R0lGODlhGAAYAPQAAP///wAAAM7Ozvr6+uDg4LCwsOjo6I6OjsjIyJycnNjY2KioqMDAwPLy8nd3d4aGhri4uGlpaQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkHAAAAIf4aQ3JlYXRlZCB3aXRoIGFqYXhsb2FkLmluZm8AIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAGAAYAAAFriAgjiQAQWVaDgr5POSgkoTDjFE0NoQ8iw8HQZQTDQjDn4jhSABhAAOhoTqSDg7qSUQwxEaEwwFhXHhHgzOA1xshxAnfTzotGRaHglJqkJcaVEqCgyoCBQkJBQKDDXQGDYaIioyOgYSXA36XIgYMBWRzXZoKBQUMmil0lgalLSIClgBpO0g+s26nUWddXyoEDIsACq5SsTMMDIECwUdJPw0Mzsu0qHYkw72bBmozIQAh+QQJBwAAACwAAAAAGAAYAAAFsCAgjiTAMGVaDgR5HKQwqKNxIKPjjFCk0KNXC6ATKSI7oAhxWIhezwhENTCQEoeGCdWIPEgzESGxEIgGBWstEW4QCGGAIJEoxGmGt5ZkgCRQQHkGd2CESoeIIwoMBQUMP4cNeQQGDYuNj4iSb5WJnmeGng0CDGaBlIQEJziHk3sABidDAHBgagButSKvAAoyuHuUYHgCkAZqebw0AgLBQyyzNKO3byNuoSS8x8OfwIchACH5BAkHAAAALAAAAAAYABgAAAW4ICCOJIAgZVoOBJkkpDKoo5EI43GMjNPSokXCINKJCI4HcCRIQEQvqIOhGhBHhUTDhGo4diOZyFAoKEQDxra2mAEgjghOpCgz3LTBIxJ5kg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CAcHCZIlCgICVgSfCEMMnA0CXaU2YSQFoQAKUQMMqjoyAglcAAyBAAIMRUYLCUkFlybDeAYJryLNk6xGNCTQXY0juHghACH5BAkHAAAALAAAAAAYABgAAAWzICCOJNA0ZVoOAmkY5KCSSgSNBDE2hDyLjohClBMNij8RJHIQvZwEVOpIekRQJyJs5AMoHA+GMbE1lnm9EcPhOHRnhpwUl3AsknHDm5RN+v8qCAkHBwkIfw1xBAYNgoSGiIqMgJQifZUjBhAJYj95ewIJCQV7KYpzBAkLLQADCHOtOpY5PgNlAAykAEUsQ1wzCgWdCIdeArczBQVbDJ0NAqyeBb64nQAGArBTt8R8mLuyPyEAOw==")
} else {
w.Write([]byte("\" data-src=\""))
w.Write(img.Attrs["data-src"])
}
return ast.GoToNext, false
}

func ParseMarkdown(markdown string) template.HTML {
// html.UnescapeString
return template.HTML(blackfriday.MarkdownCommon([]byte(markdown)))
extensions := parser.CommonExtensions
parser := parser.NewWithExtensions(extensions)

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

return template.HTML(gomk.ToHTML(gomk.NormalizeNewlines([]byte(markdown)), parser, renderer))
}

func ReplaceRootFlag(content string) string {
Expand All @@ -109,7 +147,7 @@ func ReplaceRootFlag(content string) string {
func ParseGlobalConfig(configPath string, develop bool) *GlobalConfig {
var config *GlobalConfig
// Parse Global Config
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil
}
Expand Down Expand Up @@ -145,7 +183,7 @@ func ParseGlobalConfig(configPath string, develop bool) *GlobalConfig {
func ParseThemeConfig(configPath string) *ThemeConfig {
// Read data from file
var themeConfig *ThemeConfig
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
Fatal(err.Error())
}
Expand All @@ -159,7 +197,7 @@ func ParseThemeConfig(configPath string) *ThemeConfig {
func ParseArticleConfig(markdownPath string) (config *ArticleConfig, content string) {
var configStr string
// Read data from file
data, err := ioutil.ReadFile(markdownPath)
data, err := os.ReadFile(markdownPath)
if err != nil {
Fatal(err.Error())
}
Expand Down Expand Up @@ -259,9 +297,7 @@ func ParseArticle(markdownPath string) *Article {
// Genetate custom link
if article.Type == "post" {
datePrefix := article.Time.Format("2006-01-02-")
if strings.HasPrefix(fileName, datePrefix) {
fileName = fileName[len(datePrefix):]
}
fileName = strings.TrimPrefix(fileName, datePrefix)
if globalConfig.Site.Link != "" {
linkMap := map[string]string{
"{year}": article.Time.Format("2006"),
Expand Down
15 changes: 7 additions & 8 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"html/template"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand All @@ -23,7 +22,7 @@ type RenderArticle struct {
// Compile html template
func CompileTpl(tplPath string, partialTpl string, name string) template.Template {
// Read template data from file
html, err := ioutil.ReadFile(tplPath)
html, err := os.ReadFile(tplPath)
if err != nil {
Fatal(err.Error())
}
Expand Down Expand Up @@ -64,7 +63,7 @@ func RenderPage(tpl template.Template, tplData interface{}, outPath string) {
func RenderArticles(tpl template.Template, articles Collections) {
defer wg.Done()
articleCount := len(articles)
for i, _ := range articles {
for i := range articles {
currentArticle := articles[i].(Article)
var renderArticle = RenderArticle{currentArticle, nil, nil}
if i >= 1 {
Expand Down Expand Up @@ -95,7 +94,7 @@ func GenerateRSS(articles Collections) {
Title: globalConfig.Site.Title,
Link: &feeds.Link{Href: globalConfig.Site.Url},
Description: globalConfig.Site.Subtitle,
Author: &feeds.Author{globalConfig.Site.Title, ""},
Author: &feeds.Author{Name: globalConfig.Site.Title, Email: ""},
Created: time.Now(),
}
feed.Items = make([]*feeds.Item, 0)
Expand All @@ -105,13 +104,13 @@ func GenerateRSS(articles Collections) {
Title: article.Title,
Link: &feeds.Link{Href: globalConfig.Site.Url + "/" + article.Link},
Description: string(article.Preview),
Author: &feeds.Author{article.Author.Name, ""},
Author: &feeds.Author{Name: article.Author.Name, Email: ""},
Created: article.Time,
Updated: article.MTime,
})
}
if atom, err := feed.ToAtom(); err == nil {
err := ioutil.WriteFile(filepath.Join(publicPath, "atom.xml"), []byte(atom), 0644)
err := os.WriteFile(filepath.Join(publicPath, "atom.xml"), []byte(atom), 0644)
if err != nil {
Fatal(err.Error())
}
Expand Down Expand Up @@ -179,7 +178,7 @@ func RenderArticleList(rootPath string, articles Collections, tagName string) {
func GenerateJSON(articles Collections) {
defer wg.Done()
datas := make([]map[string]interface{}, 0)
for i, _ := range articles {
for i := range articles {
article := articles[i].(Article)
var data = map[string]interface{}{
"title": article.Title,
Expand All @@ -191,5 +190,5 @@ func GenerateJSON(articles Collections) {
datas = append(datas, data)
}
str, _ := json.Marshal(datas)
ioutil.WriteFile(filepath.Join(publicPath, "index.json"), []byte(str), 0644)
os.WriteFile(filepath.Join(publicPath, "index.json"), []byte(str), 0644)
}
1 change: 1 addition & 0 deletions template/theme/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
yarn.lock
Loading