Skip to content

Commit

Permalink
refactor: remove notes support
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhsudhir committed Jul 5, 2024
1 parent b35cfbe commit 56e74c5
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 715 deletions.
12 changes: 0 additions & 12 deletions cmd/anna/anna.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) {
TagsMap: make(map[template.URL][]parser.TemplateData, 10),
CollectionsMap: make(map[template.URL][]parser.TemplateData, 10),
CollectionsSubPageLayouts: make(map[template.URL]string, 10),
Notes: make(map[template.URL]parser.Note, 10),
SiteDataPath: siteDirPath,
ErrorLogger: log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile),
RenderDrafts: cmd.RenderDrafts,
Expand All @@ -199,8 +198,6 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) {
e.DeepDataMerge.Templates = make(map[template.URL]parser.TemplateData, 10)
e.DeepDataMerge.TagsMap = make(map[template.URL][]parser.TemplateData, 10)
e.DeepDataMerge.CollectionsMap = make(map[template.URL][]parser.TemplateData, 10)
e.DeepDataMerge.Notes = make(map[template.URL]parser.Note, 10)
e.DeepDataMerge.LinkStore = make(map[template.URL][]*parser.Note, 10)

helper := helpers.Helper{
ErrorLogger: e.ErrorLogger,
Expand All @@ -216,15 +213,11 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) {

templ := p.ParseLayoutFiles()

// Generate backlinks and validations for notes
p.BackLinkParser()

e.DeepDataMerge.Templates = p.Templates
e.DeepDataMerge.TagsMap = p.TagsMap
e.DeepDataMerge.CollectionsMap = p.CollectionsMap
e.DeepDataMerge.CollectionsSubPageLayouts = p.CollectionsSubPageLayouts
e.DeepDataMerge.LayoutConfig = p.LayoutConfig
e.DeepDataMerge.Notes = p.Notes

// Copies the contents of the 'static/' directory to 'rendered/'
helper.CopyDirectoryContents(siteDirPath+"static/", siteDirPath+"rendered/static/")
Expand All @@ -248,11 +241,6 @@ func (cmd *Cmd) VanillaRender(siteDirPath string) {
e.GenerateFeed()
e.GenerateJSONIndex(siteDirPath)

e.GenerateLinkStore()
e.GenerateNoteJSONIdex(siteDirPath)

e.RenderNotes(siteDirPath, templ)
e.GenerateNoteRoot(siteDirPath, templ)
e.RenderUserDefinedPages(siteDirPath, templ)
e.RenderTags(siteDirPath, templ)
e.RenderCollections(siteDirPath, templ)
Expand Down
24 changes: 0 additions & 24 deletions pkg/engine/anna_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,6 @@ func (e *Engine) RenderCollections(fileOutPath string, templ *template.Template)
wg.Wait()
}

func (e *Engine) GenerateNoteJSONIdex(outFilePath string) {
jsonFile, err := os.Create(outFilePath + "rendered/static/noteindex.json")
if err != nil {
e.ErrorLogger.Fatal(err)
}

defer func() {
err = jsonFile.Close()
if err != nil {
e.ErrorLogger.Fatal(err)
}
}()

jsonMergedMarshaledData, err := json.Marshal(e.DeepDataMerge.Notes)
if err != nil {
e.ErrorLogger.Fatal(err)
}

_, err = jsonFile.Write(jsonMergedMarshaledData)
if err != nil {
e.ErrorLogger.Fatal(err)
}
}

func (e *Engine) GenerateJSONIndex(outFilePath string) {
// This function creates an index of the site for search
// It extracts data from the e.Templates slice
Expand Down
6 changes: 0 additions & 6 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ type DeepDataMerge struct {
// K-V pair storing the template layout name for a particular collection in the site
CollectionsSubPageLayouts map[template.URL]string

//Stores all the notes
Notes map[template.URL]parser.Note

//Stores the links of each note to other notes
LinkStore map[template.URL][]*parser.Note

// Stores the index generated for search functionality
JSONIndex map[template.URL]JSONIndexTemplate
}
Expand Down
94 changes: 0 additions & 94 deletions pkg/engine/zettel_engine.go

This file was deleted.

37 changes: 0 additions & 37 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Frontmatter struct {
Date string `yaml:"date"`
Draft bool `yaml:"draft"`
JSFiles []string `yaml:"scripts"`
Type string `yaml:"type"`
Description string `yaml:"description"`
PreviewImage string `yaml:"previewimage"`
Tags []string `yaml:"tags"`
Expand All @@ -49,10 +48,6 @@ type Frontmatter struct {
Collections []string `yaml:"collections"`
Layout string `yaml:"layout"`
CustomFields []map[string]string `yaml:"customFields"`

// Head is specifically used for
// mentioning the head of the notes
Head bool `yaml:"head"`
}

// TemplateData This struct holds all of the data required to render any page of the site
Expand Down Expand Up @@ -83,10 +78,6 @@ type Parser struct {
// Stores data parsed from layout/config.yml
LayoutConfig LayoutConfig

// Stores all the notes
Notes map[template.URL]Note

// TODO: Look into the two below fields into a single one
MdFilesName []string
MdFilesPath []string

Expand Down Expand Up @@ -172,34 +163,6 @@ func (p *Parser) AddFile(baseDirPath string, dirEntryPath string, frontmatter Fr
}

p.collectionsParser(page)

if frontmatter.Type == "note" {
markdownContent = strings.TrimFunc(markdownContent, func(r rune) bool {
return r == '\n' || r == '\t'
})

// trim the content up to n characters

if len(markdownContent) > 200 {
markdownContent = markdownContent[:200]
}

note := Note{
CompleteURL: template.URL(url),
Date: date,
Frontmatter: frontmatter,
Body: template.HTML(body),
MarkdownBody: markdownContent,
// preallocating the slice
LinkedNoteURLs: make([]template.URL, 0, 5),
LiveReload: p.LiveReload,
}

p.Notes[note.CompleteURL] = note

// NOTE: not adding the template urls of referenced ntoes
// rather, will populate it while links
}
}

func (p *Parser) ParseMarkdownContent(filecontent string, path string) (Frontmatter, string, string, bool) {
Expand Down
63 changes: 0 additions & 63 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,66 +176,3 @@ func TestParseRobots(t *testing.T) {
}
})
}

func TestNotesAndBacklinkParsing(t *testing.T) {

gotParser := parser.Parser{
Notes: make(map[template.URL]parser.Note),
ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile),
}

// creating dummy notes for testing

gotParser.Notes["notes/test/test.md"] = parser.Note{
CompleteURL: "notes/test/test.md",
Frontmatter: parser.Frontmatter{
Title: "head note",
Type: "note",
Head: true,
},
Body: "This is a [[backlink]] here",
}

gotParser.Notes["notes/test/backlink.md"] = parser.Note{
CompleteURL: "notes/test/backlink.md",
Frontmatter: parser.Frontmatter{
Title: "backlink",
Type: "note",
},
Body: "Content of note.",
}

t.Run("testing notes and backlink parsing", func(t *testing.T) {

gotParser.ParseBacklink("notes/test/test.md")

wantParser := parser.Parser{
Notes: map[template.URL]parser.Note{
"notes/test/test.md": {
CompleteURL: template.URL("notes/test/test.md"),
Frontmatter: parser.Frontmatter{
Title: "head note",
Type: "note",
Head: true,
},
Body: template.HTML("This is a <a id=\"zettel-reference\" href=\"/notes/test/backlink.md\">backlink</a> here"),
LinkedNoteURLs: []template.URL{"notes/test/backlink.md"},
},

"notes/test/backlink.md": {
CompleteURL: template.URL("notes/test/backlink.md"),
Frontmatter: parser.Frontmatter{
Title: "backlink",
Type: "note",
},
Body: template.HTML("Content of note."),
},
},
ErrorLogger: log.New(os.Stderr, "TEST ERROR\t", log.Ldate|log.Ltime|log.Lshortfile),
}

if !reflect.DeepEqual(gotParser.Notes, wantParser.Notes) {
t.Errorf("got %v,\n want %v", gotParser.Notes, wantParser.Notes)
}
})
}
Loading

0 comments on commit 56e74c5

Please sign in to comment.