From 97dd0b97b37c2a067422e8c90f2c532f9178f09d Mon Sep 17 00:00:00 2001 From: Anirudh Sudhir Date: Thu, 11 Apr 2024 15:56:13 +0530 Subject: [PATCH] feat: complete deep data merge and update tests Co-authored-by: Aditya Hegde --- .gitignore | 6 +- cmd/anna/anna.go | 6 +- pkg/engine/anna_engine.go | 80 ++++-- pkg/engine/anna_engine_test.go | 28 +- pkg/engine/engine.go | 33 ++- pkg/engine/engine_integration_test.go | 19 +- pkg/engine/engine_test.go | 12 +- pkg/engine/user_engine.go | 17 +- pkg/engine/user_engine_test.go | 12 +- pkg/parser/parser.go | 35 ++- pkg/parser/parser_integration_test.go | 4 +- pkg/parser/parser_test.go | 29 ++- site/content/posts/markdown_test.md | 245 ++++++++++++++++-- site/layout/page.layout | 25 +- site/layout/posts.layout | 2 +- site/layout/tag-subpage.layout | 12 +- site/layout/tags.layout | 11 +- site/static/index.json | 101 +++++++- test/engine/json_index_test/want_index.json | 3 +- .../posts_template.layout | 2 +- test/engine/render_page/template_input.layout | 48 +++- test/engine/render_page/want.html | 45 +++- .../render_tags/tags_subpage_template.layout | 24 +- test/engine/render_tags/tags_template.layout | 29 ++- test/engine/render_tags/want_blogs_tags.html | 22 +- test/engine/render_tags/want_tags.html | 27 +- test/engine/render_tags/want_tech_tags.html | 22 +- .../render_user_defined/template_input.layout | 48 +++- .../render_user_defined/want_index.html | 16 +- .../render_user_defined/want_post_hello.html | 16 +- test_clean.sh | 5 + 31 files changed, 724 insertions(+), 260 deletions(-) create mode 100644 test_clean.sh diff --git a/.gitignore b/.gitignore index f1febea..576c567 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -site/rendered/ anna !anna/ *.exe @@ -7,3 +6,8 @@ anna ssg/ *.txt dist/ + +#Test directories +**/rendered/ +test/**/static/ +test/**/got_sitemap.xml \ No newline at end of file diff --git a/cmd/anna/anna.go b/cmd/anna/anna.go index 6e274b2..ecc118d 100644 --- a/cmd/anna/anna.go +++ b/cmd/anna/anna.go @@ -20,16 +20,16 @@ func (cmd *Cmd) VanillaRender() { // Defining Engine and Parser Structures p := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), RenderDrafts: cmd.RenderDrafts, } e := engine.Engine{ - ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), + ErrorLogger: log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } e.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - e.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + e.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) helper := helpers.Helper{ ErrorLogger: e.ErrorLogger, diff --git a/pkg/engine/anna_engine.go b/pkg/engine/anna_engine.go index a719d85..c0b0aa1 100644 --- a/pkg/engine/anna_engine.go +++ b/pkg/engine/anna_engine.go @@ -16,28 +16,49 @@ import ( "github.com/acmpesuecc/anna/pkg/parser" ) +type TagRootTemplateData struct { + DeepDataMerge DeepDataMerge + PagePath template.URL + TagTemplateData parser.TemplateData + TagNames []string +} + func (e *Engine) RenderTags(fileOutPath string, templ *template.Template) { var tagsBuffer bytes.Buffer // Extracting tag titles - tags := make([]string, 0, len(e.DeepDataMerge.TagsMap)) + tags := make([]template.URL, 0, len(e.DeepDataMerge.TagsMap)) for tag := range e.DeepDataMerge.TagsMap { tags = append(tags, tag) } - slices.SortFunc(tags, func(a, b string) int { - return cmp.Compare(strings.ToLower(a), strings.ToLower(b)) + slices.SortFunc(tags, func(a, b template.URL) int { + return cmp.Compare(strings.ToLower(string(a)), strings.ToLower(string(b))) }) - tagNames := parser.TemplateData{ - FilenameWithoutExtension: "Tags", - Layout: e.DeepDataMerge.LayoutConfig, - Frontmatter: parser.Frontmatter{Title: "Tags"}, - Tags: tags, + tagNames := make([]string, 0, len(tags)) + for _, tag := range tags { + tagString := string(tag) + tagString, _ = strings.CutPrefix(tagString, "tags/") + tagString, _ = strings.CutSuffix(tagString, ".html") + + tagNames = append(tagNames, tagString) + } + + tagRootTemplataData := parser.TemplateData{ + Layout: e.DeepDataMerge.LayoutConfig, + Frontmatter: parser.Frontmatter{Title: "Tags"}, + } + + tagTemplateData := TagRootTemplateData{ + DeepDataMerge: e.DeepDataMerge, + PagePath: "tags.html", + TagTemplateData: tagRootTemplataData, + TagNames: tagNames, } // Rendering the page displaying all tags - err := templ.ExecuteTemplate(&tagsBuffer, "all-tags", tagNames) + err := templ.ExecuteTemplate(&tagsBuffer, "all-tags", tagTemplateData) if err != nil { e.ErrorLogger.Fatal(err) } @@ -51,23 +72,28 @@ func (e *Engine) RenderTags(fileOutPath string, templ *template.Template) { // Create a wait group to wait for all goroutines to finish var wg sync.WaitGroup + e.DeepDataMerge.Tags = make(map[template.URL]parser.TemplateData) + + for tag := range e.DeepDataMerge.TagsMap { + tagString := string(tag) + tagString, _ = strings.CutPrefix(tagString, "tags/") + tagString, _ = strings.CutSuffix(tagString, ".html") + + e.DeepDataMerge.Tags[tag] = parser.TemplateData{ + Layout: e.DeepDataMerge.LayoutConfig, + Frontmatter: parser.Frontmatter{ + Title: tagString, + }, + } + } + // Rendering the subpages with merged tagged posts for tag, taggedTemplates := range e.DeepDataMerge.TagsMap { wg.Add(1) - go func(tag string, taggedTemplates []parser.TemplateData) { + go func(tag template.URL, taggedTemplates []parser.TemplateData) { defer wg.Done() - pagePath := "tags/" + tag + ".html" - templateData := parser.TemplateData{ - FilenameWithoutExtension: tag, - Layout: e.DeepDataMerge.LayoutConfig, - Frontmatter: parser.Frontmatter{ - Title: tag, - }, - SpecificTagTemplates: taggedTemplates, - } - - e.RenderPage(fileOutPath, template.URL(pagePath), templateData, templ, "tag-subpage") + e.RenderPage(fileOutPath, template.URL(tag), templ, "tag-subpage") }(tag, taggedTemplates) } @@ -90,10 +116,8 @@ func (e *Engine) GenerateJSONIndex(outFilePath string) { jsonIndexTemplate := make(map[template.URL]JSONIndexTemplate) for templateURL, templateData := range e.DeepDataMerge.Templates { jsonIndexTemplate[templateURL] = JSONIndexTemplate{ - CompleteURL: templateData.CompleteURL, - FilenameWithoutExtension: templateData.FilenameWithoutExtension, - Frontmatter: templateData.Frontmatter, - Tags: templateData.Frontmatter.Tags, + CompleteURL: templateData.CompleteURL, + Frontmatter: templateData.Frontmatter, } } @@ -132,7 +156,7 @@ func (e *Engine) GenerateSitemap(outFilePath string) { // Iterate over parsed markdown files for _, templateData := range e.DeepDataMerge.Templates { - url := e.DeepDataMerge.LayoutConfig.BaseURL + "/" + templateData.FilenameWithoutExtension + ".html" + url := e.DeepDataMerge.LayoutConfig.BaseURL + "/" + string(templateData.CompleteURL) buffer.WriteString("\t\n") buffer.WriteString("\t\t" + url + "\n") buffer.WriteString("\t\t" + templateData.Frontmatter.Date + "\n") @@ -165,8 +189,8 @@ func (e *Engine) GenerateFeed() { if !templateData.Frontmatter.Draft { buffer.WriteString("\n") buffer.WriteString(" " + templateData.Frontmatter.Title + "\n") - buffer.WriteString(" \n") - buffer.WriteString(" " + e.DeepDataMerge.LayoutConfig.BaseURL + "/posts/" + templateData.FilenameWithoutExtension + ".html\n") + buffer.WriteString(" \n") + buffer.WriteString(" " + e.DeepDataMerge.LayoutConfig.BaseURL + string(templateData.CompleteURL) + "\n") buffer.WriteString(" " + time.Unix(templateData.Date, 0).Format(time.RFC3339) + "\n") buffer.WriteString(" \n") buffer.WriteString(" \n") diff --git a/pkg/engine/anna_engine_test.go b/pkg/engine/anna_engine_test.go index 5dcf6b0..39545ec 100644 --- a/pkg/engine/anna_engine_test.go +++ b/pkg/engine/anna_engine_test.go @@ -18,12 +18,12 @@ func TestRenderTags(t *testing.T) { ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } e.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - e.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + e.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) e.DeepDataMerge.LayoutConfig.BaseURL = "example.org" fileOutPath := "../../test/engine/render_tags/" - e.DeepDataMerge.TagsMap["blogs"] = []parser.TemplateData{ + e.DeepDataMerge.TagsMap["tags/blogs.html"] = []parser.TemplateData{ { CompleteURL: "posts/file1.html", Frontmatter: parser.Frontmatter{ @@ -40,7 +40,7 @@ func TestRenderTags(t *testing.T) { }, } - e.DeepDataMerge.TagsMap["tech"] = []parser.TemplateData{ + e.DeepDataMerge.TagsMap["tags/tech.html"] = []parser.TemplateData{ { CompleteURL: "posts/file2.html", Frontmatter: parser.Frontmatter{ @@ -112,9 +112,6 @@ func TestRenderTags(t *testing.T) { } }) - if err := os.RemoveAll(TestDirPath + "render_tags/rendered"); err != nil { - t.Errorf("%v", err) - } } func TestGenerateMergedJson(t *testing.T) { @@ -127,11 +124,10 @@ func TestGenerateMergedJson(t *testing.T) { ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } e.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - e.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + e.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) e.DeepDataMerge.Templates["docs.md"] = parser.TemplateData{ - FilenameWithoutExtension: "docs", - CompleteURL: "docs.html", + CompleteURL: "docs.html", Frontmatter: parser.Frontmatter{ Title: "Anna Documentation", }, @@ -157,9 +153,6 @@ func TestGenerateMergedJson(t *testing.T) { } }) - if err := os.RemoveAll(TestDirPath + "json_index_test/static"); err != nil { - t.Errorf("%v", err) - } } func TestGenerateSitemap(t *testing.T) { @@ -168,24 +161,24 @@ func TestGenerateSitemap(t *testing.T) { ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } engine.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - engine.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + engine.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) t1 := parser.TemplateData{ - FilenameWithoutExtension: "index", + CompleteURL: "index.html", Frontmatter: parser.Frontmatter{ Date: "2024-02-23", }, } t2 := parser.TemplateData{ - FilenameWithoutExtension: "about", + CompleteURL: "about.html", Frontmatter: parser.Frontmatter{ Date: "2024-02-23", }, } t3 := parser.TemplateData{ - FilenameWithoutExtension: "research", + CompleteURL: "research.html", Frontmatter: parser.Frontmatter{ Date: "2024-02-23", }, @@ -223,7 +216,4 @@ func TestGenerateSitemap(t *testing.T) { } }) - if err := os.RemoveAll(TestDirPath + "sitemap/got_sitemap.xml"); err != nil { - t.Errorf("%v", err) - } } diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index e6da507..e90e3e4 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -11,13 +11,16 @@ import ( ) // This struct holds all of the ssg data -type MergedSiteData struct { +type DeepDataMerge struct { // Templates stores the template data of all the pages of the site // Access the data for a particular page by using the relative path to the file as the key Templates map[template.URL]parser.TemplateData - // K-V pair storing all templates correspoding to a particular tag in the site - TagsMap map[string][]parser.TemplateData + // Templates stores the template data of all tag sub-pages of the site + Tags map[template.URL]parser.TemplateData + + // K-V pair storing all templates corresponding to a particular tag in the site + TagsMap map[template.URL][]parser.TemplateData // Stores data parsed from layout/config.yml LayoutConfig parser.LayoutConfig @@ -31,18 +34,22 @@ type MergedSiteData struct { type Engine struct { // Stores the merged ssg data - DeepDataMerge MergedSiteData + DeepDataMerge DeepDataMerge // Common logger for all engine functions ErrorLogger *log.Logger } +type PageData struct { + DeepDataMerge DeepDataMerge + + PageURL template.URL +} + // This structure is solely used for storing the JSON index type JSONIndexTemplate struct { - CompleteURL template.URL - FilenameWithoutExtension string - Frontmatter parser.Frontmatter - Tags []string + CompleteURL template.URL + Frontmatter parser.Frontmatter } /* @@ -51,13 +58,11 @@ fileOutPath - stores the parent directory to store rendered files, usually `site pagePath - stores the path to write the given page without the prefix directory Eg: site/content/posts/file1.html to be passed as posts/file1.html -pageTemplateData - an interface that accepts any type of data to be passed to ExecuteTemplate() - template - stores the HTML templates parsed from the layout/ directory templateStartString - stores the name of the template to be passed to ExecuteTemplate() */ -func (e *Engine) RenderPage(fileOutPath string, pagePath template.URL, pageTemplateData interface{}, template *template.Template, templateStartString string) { +func (e *Engine) RenderPage(fileOutPath string, pagePath template.URL, template *template.Template, templateStartString string) { // Creating subdirectories if the filepath contains '/' if strings.Contains(string(pagePath), "/") { // Extracting the directory path from the page path @@ -74,8 +79,12 @@ func (e *Engine) RenderPage(fileOutPath string, pagePath template.URL, pageTempl filepath := fileOutPath + "rendered/" + string(pagePath) var buffer bytes.Buffer + pageData := PageData{ + DeepDataMerge: e.DeepDataMerge, + PageURL: pagePath, + } // Storing the rendered HTML file to a buffer - err := template.ExecuteTemplate(&buffer, templateStartString, pageTemplateData) + err := template.ExecuteTemplate(&buffer, templateStartString, pageData) if err != nil { e.ErrorLogger.Fatal(err) } diff --git a/pkg/engine/engine_integration_test.go b/pkg/engine/engine_integration_test.go index 35e2516..2271822 100644 --- a/pkg/engine/engine_integration_test.go +++ b/pkg/engine/engine_integration_test.go @@ -16,19 +16,17 @@ func TestRenderUserDefinedPages(t *testing.T) { ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } engine.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - engine.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + engine.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) - engine.DeepDataMerge.Templates["index.md"] = + engine.DeepDataMerge.Templates["index.html"] = parser.TemplateData{ - FilenameWithoutExtension: "index", - Body: template.HTML("

Index Page

"), - CompleteURL: "index.html", + Body: template.HTML("

Index Page

"), + CompleteURL: "index.html", } - engine.DeepDataMerge.Templates["posts/hello.md"] = parser.TemplateData{ - FilenameWithoutExtension: "hello", - Body: template.HTML("

Hello World

"), - CompleteURL: "posts/hello.html", + engine.DeepDataMerge.Templates["posts/hello.html"] = parser.TemplateData{ + Body: template.HTML("

Hello World

"), + CompleteURL: "posts/hello.html", } if err := os.MkdirAll(TestDirPath+"render_user_defined/rendered", 0750); err != nil { @@ -73,7 +71,4 @@ func TestRenderUserDefinedPages(t *testing.T) { } }) - if err := os.RemoveAll(TestDirPath + "render_user_defined/rendered"); err != nil { - t.Errorf("%v", err) - } } diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go index 21538f8..7c44c17 100644 --- a/pkg/engine/engine_test.go +++ b/pkg/engine/engine_test.go @@ -23,11 +23,10 @@ func TestRenderPage(t *testing.T) { ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } engine.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - engine.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + engine.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) - page := parser.TemplateData{ - CompleteURL: template.URL("got"), - FilenameWithoutExtension: "got", + engine.DeepDataMerge.Templates["posts/got.html"] = parser.TemplateData{ + CompleteURL: template.URL("got.html"), Frontmatter: parser.Frontmatter{ Title: "Hello", Date: "2024-03-28", @@ -50,7 +49,7 @@ func TestRenderPage(t *testing.T) { t.Errorf("%v", err) } - engine.RenderPage(TestDirPath+"render_page/", "posts/got.html", page, templ, "page") + engine.RenderPage(TestDirPath+"render_page/", "posts/got.html", templ, "page") got_file, err := os.ReadFile(TestDirPath + "render_page/rendered/posts/got.html") if err != nil { @@ -67,7 +66,4 @@ func TestRenderPage(t *testing.T) { } }) - if err := os.RemoveAll(TestDirPath + "render_page/rendered"); err != nil { - t.Errorf("%v", err) - } } diff --git a/pkg/engine/user_engine.go b/pkg/engine/user_engine.go index 3b10d47..4b19b57 100644 --- a/pkg/engine/user_engine.go +++ b/pkg/engine/user_engine.go @@ -16,7 +16,7 @@ type postsTemplateData struct { parser.TemplateData } -func (e *Engine) RenderEngineGeneratedFiles(fileOutPath string, templ *template.Template) { +func (e *Engine) RenderEngineGeneratedFiles(fileOutPath string, template *template.Template) { // Rendering "posts.html" var postsBuffer bytes.Buffer @@ -27,8 +27,16 @@ func (e *Engine) RenderEngineGeneratedFiles(fileOutPath string, templ *template. Layout: e.DeepDataMerge.LayoutConfig, }, } + // e.DeepDataMerge.Templates["posts.html"] = parser.TemplateData{ + // Frontmatter: parser.Frontmatter{Title: "Posts"}, + // } - err := templ.ExecuteTemplate(&postsBuffer, "posts", postsData) + // pageData := PageData{ + // DeepDataMerge: e.DeepDataMerge, + // PageURL: "posts.html", + // } + + err := template.ExecuteTemplate(&postsBuffer, "posts", postsData) if err != nil { e.ErrorLogger.Fatal(err) } @@ -58,8 +66,7 @@ func (e *Engine) RenderUserDefinedPages(fileOutPath string, templ *template.Temp semaphore := make(chan struct{}, concurrency) for _, templateURL := range templateURLs { - templData := e.DeepDataMerge.Templates[template.URL(templateURL)] - fileInPath := strings.TrimSuffix(string(templData.CompleteURL), ".html") + fileInPath := strings.TrimSuffix(templateURL, ".html") if fileInPath == ".html" { continue } @@ -73,7 +80,7 @@ func (e *Engine) RenderUserDefinedPages(fileOutPath string, templ *template.Temp wg.Done() }() - e.RenderPage(fileOutPath, templData.CompleteURL, templData, templ, "page") + e.RenderPage(fileOutPath, template.URL(templateURL), templ, "page") }(templateURL) } diff --git a/pkg/engine/user_engine_test.go b/pkg/engine/user_engine_test.go index 02c29be..1ac3670 100644 --- a/pkg/engine/user_engine_test.go +++ b/pkg/engine/user_engine_test.go @@ -17,11 +17,11 @@ func TestRenderEngineGeneratedFiles(t *testing.T) { ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } engine.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData) - engine.DeepDataMerge.TagsMap = make(map[string][]parser.TemplateData) + engine.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData) engine.DeepDataMerge.Posts = []parser.TemplateData{ { - FilenameWithoutExtension: "file1", + CompleteURL: "posts/file1.html", Frontmatter: parser.Frontmatter{ Title: "file1", Description: "Description of file 1", @@ -30,7 +30,7 @@ func TestRenderEngineGeneratedFiles(t *testing.T) { }, { - FilenameWithoutExtension: "file2", + CompleteURL: "posts/file2.html", Frontmatter: parser.Frontmatter{ Title: "file2", Description: "Description of file 2", @@ -39,7 +39,7 @@ func TestRenderEngineGeneratedFiles(t *testing.T) { }, { - FilenameWithoutExtension: "file3", + CompleteURL: "posts/file3.html", Frontmatter: parser.Frontmatter{ Title: "file3", Description: "Description of file 3", @@ -74,8 +74,4 @@ func TestRenderEngineGeneratedFiles(t *testing.T) { t.Errorf("The expected and generated posts.html can be found in test/engine/render_engine_generated/rendered/") } }) - - if err := os.RemoveAll(TestDirPath + "render_engine_generated/rendered"); err != nil { - t.Errorf("%v", err) - } } diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index db7c7e9..e574afb 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -40,17 +40,11 @@ type Frontmatter struct { // This struct holds all of the data required to render any page of the site type TemplateData struct { - CompleteURL template.URL - FilenameWithoutExtension string - Date int64 - Frontmatter Frontmatter - Body template.HTML - Layout LayoutConfig - - // Do not use these fields to store tags!! - // These fields are populated by the ssg to store merged tag data - Tags []string - SpecificTagTemplates []TemplateData + CompleteURL template.URL + Date int64 + Frontmatter Frontmatter + Body template.HTML + Layout LayoutConfig } type Date int64 @@ -61,7 +55,7 @@ type Parser struct { Templates map[template.URL]TemplateData // K-V pair storing all templates correspoding to a particular tag in the site - TagsMap map[string][]TemplateData + TagsMap map[template.URL][]TemplateData // Stores data parsed from layout/config.yml LayoutConfig LayoutConfig @@ -128,13 +122,13 @@ func (p *Parser) AddFileAndRender(baseDirPath string, dirEntryPath string, front if frontmatter.Type == "post" { url = "posts/" + url } + page := TemplateData{ - CompleteURL: template.URL(url), - Date: date, - FilenameWithoutExtension: strings.Split(dirEntryPath, ".")[0], - Frontmatter: frontmatter, - Body: template.HTML(body), - Layout: p.LayoutConfig, + CompleteURL: template.URL(url), + Date: date, + Frontmatter: frontmatter, + Body: template.HTML(body), + Layout: p.LayoutConfig, } // Adding the page to the merged map storing all site pages @@ -142,11 +136,12 @@ func (p *Parser) AddFileAndRender(baseDirPath string, dirEntryPath string, front p.Posts = append(p.Posts, page) } - p.Templates[template.URL(key)] = page + p.Templates[template.URL(url)] = page // Adding the page to the tags map with the corresponding tags for _, tag := range page.Frontmatter.Tags { - p.TagsMap[tag] = append(p.TagsMap[tag], page) + tagsMapKey := "tags/" + tag + ".html" + p.TagsMap[template.URL(tagsMapKey)] = append(p.TagsMap[template.URL(tagsMapKey)], page) } } diff --git a/pkg/parser/parser_integration_test.go b/pkg/parser/parser_integration_test.go index cf863f8..bbbb40e 100644 --- a/pkg/parser/parser_integration_test.go +++ b/pkg/parser/parser_integration_test.go @@ -13,7 +13,7 @@ func TestParseMDDir(t *testing.T) { t.Run("reading markdown files and rendering without drafts", func(t *testing.T) { p := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } p.RenderDrafts = false @@ -33,7 +33,7 @@ func TestParseMDDir(t *testing.T) { t.Run("reading all markdown files inluding drafts", func(t *testing.T) { p := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } p.RenderDrafts = true diff --git a/pkg/parser/parser_test.go b/pkg/parser/parser_test.go index ea60dc4..8c6d7b9 100644 --- a/pkg/parser/parser_test.go +++ b/pkg/parser/parser_test.go @@ -16,7 +16,7 @@ const TestDirPath = "../../test/parser/" func TestAddFileandRender(t *testing.T) { got_parser := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } @@ -34,10 +34,11 @@ func TestAddFileandRender(t *testing.T) { } want_parser := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: got_parser.ErrorLogger, } - sample_frontmatter, sample_body, parseSuccess := got_parser.ParseMarkdownContent(string(inputMd)) + sample_frontmatter, _, parseSuccess := got_parser.ParseMarkdownContent(string(inputMd)) + sample_body := "sample_body" if !parseSuccess { return } @@ -47,18 +48,17 @@ func TestAddFileandRender(t *testing.T) { want_parser.MdFilesName = append(want_parser.MdFilesName, filename) want_parser.MdFilesPath = append(want_parser.MdFilesPath, filename) want_page := parser.TemplateData{ - CompleteURL: template.URL(fileurl), - Date: want_parser.DateParse(sample_frontmatter.Date).Unix(), - FilenameWithoutExtension: "testpost", - Frontmatter: sample_frontmatter, - Body: template.HTML(sample_body), - Layout: want_layout, + CompleteURL: template.URL(fileurl), + Date: want_parser.DateParse(sample_frontmatter.Date).Unix(), + Frontmatter: sample_frontmatter, + Body: template.HTML(sample_body), + Layout: want_layout, } want_parser.LayoutConfig = want_layout - want_parser.Templates[template.URL("testpost.md")] = want_page + want_parser.Templates[template.URL("posts/testpost.html")] = want_page for _, tag := range sample_frontmatter.Tags { - want_parser.TagsMap[tag] = append(want_parser.TagsMap[tag], want_page) + want_parser.TagsMap[template.URL(tag)] = append(want_parser.TagsMap[template.URL(tag)], want_page) } if sample_frontmatter.Type == "post" { @@ -69,6 +69,7 @@ func TestAddFileandRender(t *testing.T) { if !reflect.DeepEqual(got_parser, want_parser) { t.Errorf("want %v; \ngot %v", want_parser, got_parser) + // t.Errorf("please see the files yourself") } }) } @@ -76,7 +77,7 @@ func TestAddFileandRender(t *testing.T) { func TestParseMarkdownContent(t *testing.T) { p := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } t.Run("render markdown files to html", func(t *testing.T) { @@ -126,7 +127,7 @@ func TestParseConfig(t *testing.T) { t.Run("unmarshal `config.yml` to LayoutConfig", func(t *testing.T) { got_parser := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } @@ -149,7 +150,7 @@ func TestParseRobots(t *testing.T) { t.Run("parse and render `robots.txt`", func(t *testing.T) { parser := parser.Parser{ Templates: make(map[template.URL]parser.TemplateData), - TagsMap: make(map[string][]parser.TemplateData), + TagsMap: make(map[template.URL][]parser.TemplateData), ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile), } parser.LayoutConfig.BaseURL = "example.org" diff --git a/site/content/posts/markdown_test.md b/site/content/posts/markdown_test.md index 686ad71..4edfdce 100644 --- a/site/content/posts/markdown_test.md +++ b/site/content/posts/markdown_test.md @@ -1,27 +1,242 @@ --- title: Sample Post -author: John Doe date: 2024-02-23 -categories: - - Technology - - Programming -scripts: type: post draft: true tags: - - test-post + - testing --- -# heading L1 +# h1 Heading 8-) +## h2 Heading +### h3 Heading +#### h4 Heading +##### h5 Heading +###### h6 Heading -Lorem ipsum dolor sit amet, officia excepteur ex fugiat reprehenderit enim -labore culpa sint ad nisi Lorem pariatur mollit ex esse exercitation amet. Nisi -anim cupidatat excepteur officia. Reprehenderit nostrud nostrud ipsum Lorem est -aliquip amet voluptate voluptate dolor minim nulla est proident. Nostrud -officia pariatur ut officia. Sit irure elit esse ea nulla sunt ex occaecat -## heading L2 +## Horizontal Rules -**_bold and italics_** +___ -> quote text +--- + +*** + + +## Typographic replacements + +Enable typographer option to see result. + +(c) (C) (r) (R) (tm) (TM) (p) (P) +- + +test.. test... test..... test?..... test!.... + +!!!!!! ???? ,, -- --- + +"Smartypants, double quotes" and 'single quotes' + + +## Emphasis + +**This is bold text** + +__This is bold text__ + +*This is italic text* + +_This is italic text_ + +~~Strikethrough~~ + + +## Blockquotes + + +> Blockquotes can also be nested... +>> ...by using additional greater-than signs right next to each other... +> > > ...or with spaces between arrows. + + +## Lists + +Unordered + ++ Create a list by starting a line with `+`, `-`, or `*` ++ Sub-lists are made by indenting 2 spaces: + - Marker character change forces new list start: + * Ac tristique libero volutpat at + + Facilisis in pretium nisl aliquet + - Nulla volutpat aliquam velit ++ Very easy! + +Ordered + +1. Lorem ipsum dolor sit amet +2. Consectetur adipiscing elit +3. Integer molestie lorem at massa + + +1. You can use sequential numbers... +1. ...or keep all the numbers as `1.` + +Start numbering with offset: + +57. foo +1. bar + + +## Code + +Inline `code` + +Indented code + + // Some comments + line 1 of code + line 2 of code + line 3 of code + + +Block code "fences" + +``` +Sample text here... +``` + +Syntax highlighting + +``` js +var foo = function (bar) { + return bar++; +}; + +console.log(foo(5)); +``` + +## Tables + +| Option | Description | +| ------ | ----------- | +| data | path to data files to supply the data that will be passed into templates. | +| engine | engine to be used for processing templates. Handlebars is the default. | +| ext | extension to be used for dest files. | + +Right aligned columns + +| Option | Description | +| ------:| -----------:| +| data | path to data files to supply the data that will be passed into templates. | +| engine | engine to be used for processing templates. Handlebars is the default. | +| ext | extension to be used for dest files. | + + +## Links + +[link text](http://dev.nodeca.com) + +[link with title](http://nodeca.github.io/pica/demo/ "title text!") + +Autoconverted link https://github.com/nodeca/pica (enable linkify to see) + + +## Images + +![Minion](https://octodex.github.com/images/minion.png) +![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat") + +Like links, Images also have a footnote style syntax + +![Alt text][id] + +With a reference later in the document defining the URL location: + +[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat" + + +## Plugins + +The killer feature of `markdown-it` is very effective support of +[syntax plugins](https://www.npmjs.org/browse/keyword/markdown-it-plugin). + + +### [Emojies](https://github.com/markdown-it/markdown-it-emoji) + +> Classic markup: :wink: :cry: :laughing: :yum: +> +> Shortcuts (emoticons): :-) :-( 8-) ;) + +see [how to change output](https://github.com/markdown-it/markdown-it-emoji#change-output) with twemoji. + + +### [Subscript](https://github.com/markdown-it/markdown-it-sub) / [Superscript](https://github.com/markdown-it/markdown-it-sup) + +- 19^th^ +- H~2~O + + +### [\](https://github.com/markdown-it/markdown-it-ins) + +++Inserted text++ + + +### [\](https://github.com/markdown-it/markdown-it-mark) + +==Marked text== + + +### [Footnotes](https://github.com/markdown-it/markdown-it-footnote) + +Footnote 1 link[^first]. + +Footnote 2 link[^second]. + +Inline footnote^[Text of inline footnote] definition. + +Duplicated footnote reference[^second]. + +[^first]: Footnote **can have markup** + + and multiple paragraphs. + +[^second]: Footnote text. + + +### [Definition lists](https://github.com/markdown-it/markdown-it-deflist) + +Term 1 + +: Definition 1 +with lazy continuation. + +Term 2 with *inline markup* + +: Definition 2 + + { some code, part of Definition 2 } + + Third paragraph of definition 2. + +_Compact style:_ + +Term 1 + ~ Definition 1 + +Term 2 + ~ Definition 2a + ~ Definition 2b + + +### [Abbreviations](https://github.com/markdown-it/markdown-it-abbr) + +This is HTML abbreviation example. + +It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on. + +*[HTML]: Hyper Text Markup Language + +### [Custom containers](https://github.com/markdown-it/markdown-it-container) + +::: warning +*here be dragons* +::: diff --git a/site/layout/page.layout b/site/layout/page.layout index 84a2478..3ffc6eb 100644 --- a/site/layout/page.layout +++ b/site/layout/page.layout @@ -1,29 +1,30 @@ {{ define "page"}} -{{ template "head" .}} +{{$PageData := index .DeepDataMerge.Templates .PageURL}} +{{ template "head" $PageData}} - {{template "header" .}} + {{template "header" $PageData}}
- {{ if eq .Frontmatter.Type "post" }} + {{ if eq $PageData.Frontmatter.Type "post" }}
-

{{ .Frontmatter.Title }}

+

{{ $PageData.Frontmatter.Title }}

- Published on {{.Frontmatter.Date}} + Published on {{$PageData.Frontmatter.Date}} - {{ if eq (len .Frontmatter.Authors) 0 }} - {{$.Layout.Author}} + {{ if eq (len $PageData.Frontmatter.Authors) 0 }} + {{.DeepDataMerge.LayoutConfig.Author}} {{ else }} - {{range .Frontmatter.Authors }} + {{range $PageData.Frontmatter.Authors }} {{ . }}, {{ end }} {{ end }}

- {{range .Frontmatter.Tags}} + {{range $PageData.Frontmatter.Tags}} @@ -32,12 +33,12 @@
{{ else }} {{ end }} - {{.Body}} + {{$PageData.Body}}
- {{template "footer" .}} + {{template "footer" $PageData}} -{{ end}} \ No newline at end of file +{{ end}} diff --git a/site/layout/posts.layout b/site/layout/posts.layout index 255fd71..c0e3fd5 100644 --- a/site/layout/posts.layout +++ b/site/layout/posts.layout @@ -7,7 +7,7 @@
{{range $PostDate, $Post := .Posts}} - +

{{$Post.Frontmatter.Title}}

{{$Post.Frontmatter.Description}}

diff --git a/site/layout/tag-subpage.layout b/site/layout/tag-subpage.layout index 2fc403c..bc11c87 100644 --- a/site/layout/tag-subpage.layout +++ b/site/layout/tag-subpage.layout @@ -1,22 +1,24 @@ {{ define "tag-subpage"}} -{{ template "head" .}} +{{$PageData := index .DeepDataMerge.Tags .PageURL}} +{{ template "head" $PageData}} - {{template "header" .}} + {{template "header" $PageData}}
- {{template "footer" .}} + {{template "footer" $PageData}} -{{ end}} \ No newline at end of file +{{ end}} diff --git a/site/layout/tags.layout b/site/layout/tags.layout index 3aa6dce..6837776 100644 --- a/site/layout/tags.layout +++ b/site/layout/tags.layout @@ -1,14 +1,15 @@ {{ define "all-tags"}} -{{ template "head" .}} +{{$PageData := .TagTemplateData}} +{{ template "head" $PageData}} - {{template "header" .}} +{{template "header" $PageData}}
- {{range .Tags}} - {{.}} + {{range .TagNames}} + {{.}} {{end}}
@@ -19,7 +20,7 @@ - {{template "footer" .}} + {{template "footer" $PageData}} diff --git a/site/static/index.json b/site/static/index.json index 33cad2e..61c8828 100644 --- a/site/static/index.json +++ b/site/static/index.json @@ -1 +1,100 @@ -{"bench.md":{"CompleteURL":"posts/bench.html","FilenameWithoutExtension":"bench","Frontmatter":{"Title":"benchmark","Date":"2024-01-01","Draft":false,"JSFiles":null,"Type":"post","Description":"","PreviewImage":"","Tags":["test-post"],"Authors":null},"Tags":["test-post"]},"building_anna.md":{"CompleteURL":"posts/building_anna.html","FilenameWithoutExtension":"building_anna","Frontmatter":{"Title":"Building anna","Date":"2024-04-04","Draft":false,"JSFiles":null,"Type":"post","Description":"This page contains a post about anna, a static site generator written in Go. This team project was built as part of AIEP 2024","PreviewImage":"","Tags":["acm","hsp","go","tech","talk","aiep"],"Authors":["Adhesh","Aditya","Nathan","Anirudh"]},"Tags":["acm","hsp","go","tech","talk","aiep"]},"docs.md":{"CompleteURL":"docs.html","FilenameWithoutExtension":"docs","Frontmatter":{"Title":"Anna Documentation","Date":"2024-04-10","Draft":false,"JSFiles":null,"Type":"","Description":"","PreviewImage":"","Tags":null,"Authors":null},"Tags":null},"index.md":{"CompleteURL":"index.html","FilenameWithoutExtension":"index","Frontmatter":{"Title":"Home","Date":"2024-02-24","Draft":false,"JSFiles":null,"Type":"","Description":"homepage for our ssg","PreviewImage":"/static/plane.jpg","Tags":null,"Authors":null},"Tags":null},"week-1.md":{"CompleteURL":"posts/week-1.html","FilenameWithoutExtension":"week-1","Frontmatter":{"Title":"Week-1 Progress","Date":"2024-03-18","Draft":false,"JSFiles":null,"Type":"post","Description":"","PreviewImage":"","Tags":["progress"],"Authors":["Adhesh","Aditya","Anirudh","Nathan"]},"Tags":["progress"]},"week-2.md":{"CompleteURL":"posts/week-2.html","FilenameWithoutExtension":"week-2","Frontmatter":{"Title":"Week-2 Progress","Date":"2024-03-25","Draft":false,"JSFiles":null,"Type":"post","Description":"","PreviewImage":"","Tags":["progress"],"Authors":["Adhesh","Aditya","Anirudh","Nathan"]},"Tags":["progress"]},"week-3.md":{"CompleteURL":"posts/week-3.html","FilenameWithoutExtension":"week-3","Frontmatter":{"Title":"Week-3 Progress","Date":"2024-04-01","Draft":false,"JSFiles":null,"Type":"post","Description":"","PreviewImage":"","Tags":["progress"],"Authors":["Adhesh","Aditya","Anirudh","Nathan"]},"Tags":["progress"]}} \ No newline at end of file +{ + "docs.html": { + "CompleteURL": "docs.html", + "Frontmatter": { + "Title": "Anna Documentation", + "Date": "2024-04-10", + "Draft": false, + "JSFiles": null, + "Type": "", + "Description": "", + "PreviewImage": "", + "Tags": null, + "Authors": null + } + }, + "index.html": { + "CompleteURL": "index.html", + "Frontmatter": { + "Title": "Home", + "Date": "2024-02-24", + "Draft": false, + "JSFiles": null, + "Type": "", + "Description": "homepage for our ssg", + "PreviewImage": "/static/plane.jpg", + "Tags": null, + "Authors": null + } + }, + "posts/bench.html": { + "CompleteURL": "posts/bench.html", + "Frontmatter": { + "Title": "benchmark", + "Date": "2024-01-01", + "Draft": false, + "JSFiles": null, + "Type": "post", + "Description": "", + "PreviewImage": "", + "Tags": ["test-post"], + "Authors": null + } + }, + "posts/building_anna.html": { + "CompleteURL": "posts/building_anna.html", + "Frontmatter": { + "Title": "Building anna", + "Date": "2024-04-04", + "Draft": false, + "JSFiles": null, + "Type": "post", + "Description": "This page contains a post about anna, a static site generator written in Go. This team project was built as part of AIEP 2024", + "PreviewImage": "", + "Tags": ["acm", "hsp", "go", "tech", "talk", "aiep"], + "Authors": ["Adhesh", "Aditya", "Nathan", "Anirudh"] + } + }, + "posts/week-1.html": { + "CompleteURL": "posts/week-1.html", + "Frontmatter": { + "Title": "Week-1 Progress", + "Date": "2024-03-18", + "Draft": false, + "JSFiles": null, + "Type": "post", + "Description": "", + "PreviewImage": "", + "Tags": ["progress"], + "Authors": ["Adhesh", "Aditya", "Anirudh", "Nathan"] + } + }, + "posts/week-2.html": { + "CompleteURL": "posts/week-2.html", + "Frontmatter": { + "Title": "Week-2 Progress", + "Date": "2024-03-25", + "Draft": false, + "JSFiles": null, + "Type": "post", + "Description": "", + "PreviewImage": "", + "Tags": ["progress"], + "Authors": ["Adhesh", "Aditya", "Anirudh", "Nathan"] + } + }, + "posts/week-3.html": { + "CompleteURL": "posts/week-3.html", + "Frontmatter": { + "Title": "Week-3 Progress", + "Date": "2024-04-01", + "Draft": false, + "JSFiles": null, + "Type": "post", + "Description": "", + "PreviewImage": "", + "Tags": ["progress"], + "Authors": ["Adhesh", "Aditya", "Anirudh", "Nathan"] + } + } +} diff --git a/test/engine/json_index_test/want_index.json b/test/engine/json_index_test/want_index.json index c8c3fa1..a6f6b45 100644 --- a/test/engine/json_index_test/want_index.json +++ b/test/engine/json_index_test/want_index.json @@ -1,2 +1 @@ -{"docs.md":{"CompleteURL":"docs.html","FilenameWithoutExtension":"docs","Frontmatter":{"Title":"Anna Documentation","Date":"","Draft":false,"JSFiles":null,"Type":"","Description":"","PreviewImage":"","Tags":null,"Authors":null},"Tags":null}} - +{"docs.md":{"CompleteURL":"docs.html","Frontmatter":{"Title":"Anna Documentation","Date":"","Draft":false,"JSFiles":null,"Type":"","Description":"","PreviewImage":"","Tags":null,"Authors":null}}} diff --git a/test/engine/render_engine_generated/posts_template.layout b/test/engine/render_engine_generated/posts_template.layout index 83673a2..12b2fa0 100644 --- a/test/engine/render_engine_generated/posts_template.layout +++ b/test/engine/render_engine_generated/posts_template.layout @@ -4,7 +4,7 @@
{{range $PostDate, $Post := .Posts}} - +

{{$Post.Frontmatter.Title}}

diff --git a/test/engine/render_page/template_input.layout b/test/engine/render_page/template_input.layout index d10c4ad..028c8e0 100644 --- a/test/engine/render_page/template_input.layout +++ b/test/engine/render_page/template_input.layout @@ -1,15 +1,39 @@ {{ define "page"}} - - +{{$PageData := index .DeepDataMerge.Templates .PageURL}} + -
-{{.Body}} + +
+
+ {{ if eq $PageData.Frontmatter.Type "post" }} +
+

{{ $PageData.Frontmatter.Title }}

+
+

+ Published on {{$PageData.Frontmatter.Date}} + + {{ if eq (len $PageData.Frontmatter.Authors) 0 }} + {{.DeepDataMerge.LayoutConfig.Author}} + {{ else }} + {{range $PageData.Frontmatter.Authors }} + {{ . }}, + {{ end }} + {{ end }} +

+
+
+ {{range $PageData.Frontmatter.Tags}} +
+ {{.}} +
+ {{end}} +
+
+ {{ else }} + {{ end }} + {{$PageData.Body}} +
+
- -{{end}} + +{{ end}} diff --git a/test/engine/render_page/want.html b/test/engine/render_page/want.html index 6cfcd99..74a18c8 100644 --- a/test/engine/render_page/want.html +++ b/test/engine/render_page/want.html @@ -1,18 +1,37 @@ - - - -
-
-blog -
- + -
-

Hello World

+
+
+ +
+

Hello

+
+

+ Published on 2024-03-28 + + + + +

+
+
+ +
+ blog +
+ +
+ thoughts +
+ +
+
+ +

Hello World

+
+
- + diff --git a/test/engine/render_tags/tags_subpage_template.layout b/test/engine/render_tags/tags_subpage_template.layout index 3a3e44b..db17318 100644 --- a/test/engine/render_tags/tags_subpage_template.layout +++ b/test/engine/render_tags/tags_subpage_template.layout @@ -1,12 +1,18 @@ {{ define "tag-subpage"}} +{{$PageData := index .DeepDataMerge.Tags .PageURL}} + -
-
-{{ range .SpecificTagTemplates }} -{{ .Frontmatter.Title }} -{{ end }} -
-
+ +
+
+
+ {{$TagSet := index .DeepDataMerge.TagsMap .PageURL}} + {{range $TagSet }} + {{.Frontmatter.Title}} + {{end}} +
+
+
+ - -{{ end }} +{{ end}} diff --git a/test/engine/render_tags/tags_template.layout b/test/engine/render_tags/tags_template.layout index cb350e1..ed5f1ba 100644 --- a/test/engine/render_tags/tags_template.layout +++ b/test/engine/render_tags/tags_template.layout @@ -1,12 +1,25 @@ {{ define "all-tags"}} +{{$PageData := .TagTemplateData}} + -
-
-{{ range .Tags }} -{{.}} -{{end}} -
-
+
+
+
+
+ {{range .TagNames}} + {{.}} + {{end}} +
+
+
+
+ +
+ + + + -{{ end }} + +{{ end}} diff --git a/test/engine/render_tags/want_blogs_tags.html b/test/engine/render_tags/want_blogs_tags.html index 3d48ac2..417ba83 100644 --- a/test/engine/render_tags/want_blogs_tags.html +++ b/test/engine/render_tags/want_blogs_tags.html @@ -1,13 +1,19 @@ - -
-
-file1 -file2 + + +
+ +
-
-
- diff --git a/test/engine/render_tags/want_tags.html b/test/engine/render_tags/want_tags.html index 1c73adc..243f780 100644 --- a/test/engine/render_tags/want_tags.html +++ b/test/engine/render_tags/want_tags.html @@ -1,13 +1,26 @@ - -
-
-blogs -tech + +
+ +
+ +
+ + -
-
+ + diff --git a/test/engine/render_tags/want_tech_tags.html b/test/engine/render_tags/want_tech_tags.html index 88497f7..1dbd4e7 100644 --- a/test/engine/render_tags/want_tech_tags.html +++ b/test/engine/render_tags/want_tech_tags.html @@ -1,13 +1,19 @@ - -
-
-file2 -file3 + + +
+ +
-
-
- diff --git a/test/engine/render_user_defined/template_input.layout b/test/engine/render_user_defined/template_input.layout index d10c4ad..86f9ef2 100644 --- a/test/engine/render_user_defined/template_input.layout +++ b/test/engine/render_user_defined/template_input.layout @@ -1,15 +1,41 @@ {{ define "page"}} - - +{{$PageData := index .DeepDataMerge.Templates .PageURL}} + -
-{{range .Frontmatter.Tags}} -
-{{.}} -
-{{end}} -
-{{.Body}} + +
+
+ {{ if eq $PageData.Frontmatter.Type "post" }} +
+

{{ $PageData.Frontmatter.Title }}

+
+

+ Published on {{$PageData.Frontmatter.Date}} + + {{ if eq (len $PageData.Frontmatter.Authors) 0 }} + {{.DeepDataMerge.LayoutConfig.Author}} + {{ else }} + {{range $PageData.Frontmatter.Authors }} + {{ . }}, + {{ end }} + {{ end }} +

+
+
+ {{range $PageData.Frontmatter.Tags}} +
+ {{.}} +
+ {{end}} +
+
+ {{ else }} + {{ end }} + {{$PageData.Body}} +
+
+ -{{end}} + +{{ end}} diff --git a/test/engine/render_user_defined/want_index.html b/test/engine/render_user_defined/want_index.html index c3dcf98..b6923df 100644 --- a/test/engine/render_user_defined/want_index.html +++ b/test/engine/render_user_defined/want_index.html @@ -1,10 +1,16 @@ - - + + -
-
-

Index Page

+
+
+ + +

Index Page

+
+
+ + diff --git a/test/engine/render_user_defined/want_post_hello.html b/test/engine/render_user_defined/want_post_hello.html index d4fc935..3364574 100644 --- a/test/engine/render_user_defined/want_post_hello.html +++ b/test/engine/render_user_defined/want_post_hello.html @@ -1,10 +1,16 @@ - - + + -
-
-

Hello World

+
+
+ + +

Hello World

+
+
+ + diff --git a/test_clean.sh b/test_clean.sh new file mode 100644 index 0000000..0b34da1 --- /dev/null +++ b/test_clean.sh @@ -0,0 +1,5 @@ +#This script can be utilised to clean the test output data + +cd test/ +rm -rf `find . -type d -name rendered` +cd ../ \ No newline at end of file