diff --git a/pkg/engine/anna_engine.go b/pkg/engine/anna_engine.go index f801968..77b3ae7 100644 --- a/pkg/engine/anna_engine.go +++ b/pkg/engine/anna_engine.go @@ -4,6 +4,7 @@ import ( "bytes" "cmp" "encoding/json" + "encoding/xml" "html/template" "os" "slices" @@ -212,27 +213,61 @@ func (e *Engine) GenerateSitemap(outFilePath string) { func (e *Engine) GenerateFeed() { var buffer bytes.Buffer - buffer.WriteString("\n") + buffer.WriteString("\n") buffer.WriteString("\n") - buffer.WriteString("\n") - buffer.WriteString(" " + e.DeepDataMerge.LayoutConfig.SiteTitle + "\n") - buffer.WriteString(" \n") - buffer.WriteString(" " + time.Now().Format(time.RFC3339) + "\n") - - // iterate over parsed markdown files that are non-draft posts + buffer.WriteString("\n") + buffer.WriteString(" \n") + buffer.WriteString(" ") + xml.EscapeText(&buffer, []byte(e.DeepDataMerge.LayoutConfig.SiteTitle)) + buffer.WriteString("\n") + buffer.WriteString(" " + e.DeepDataMerge.LayoutConfig.BaseURL + "/" + "\n") + buffer.WriteString(" Recent content on ") + xml.EscapeText(&buffer, []byte(e.DeepDataMerge.LayoutConfig.SiteTitle)) + buffer.WriteString("\n") + buffer.WriteString(" en-IN\n") + buffer.WriteString(" ") + xml.EscapeText(&buffer, []byte(e.DeepDataMerge.LayoutConfig.Author)) + buffer.WriteString("\n") + buffer.WriteString(" ") + xml.EscapeText(&buffer, []byte(e.DeepDataMerge.LayoutConfig.Copyright)) + buffer.WriteString("\n") + buffer.WriteString(" " + time.Now().Format(time.RFC1123Z) + "\n") + buffer.WriteString(" \n") + + // slice + var posts []parser.TemplateData for _, templateData := range e.DeepDataMerge.Templates { if !templateData.Frontmatter.Draft { - buffer.WriteString("\n") - buffer.WriteString(" " + templateData.Frontmatter.Title + "\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") + posts = append(posts, templateData) } } - buffer.WriteString("\n") + // sort by publication date + sort.Slice(posts, func(i, j int) bool { + return posts[i].Date > posts[j].Date // assuming Date is Unix timestamp + }) + + // Iterate over sorted posts + for _, templateData := range posts { + buffer.WriteString(" \n") + buffer.WriteString(" ") + xml.EscapeText(&buffer, []byte(templateData.Frontmatter.Title)) + buffer.WriteString("\n") + buffer.WriteString(" " + e.DeepDataMerge.LayoutConfig.BaseURL + "/" + string(templateData.CompleteURL) + "/\n") + buffer.WriteString(" " + time.Unix(templateData.Date, 0).Format(time.RFC1123Z) + "\n") + buffer.WriteString(" ") + xml.EscapeText(&buffer, []byte(e.DeepDataMerge.LayoutConfig.Author)) + buffer.WriteString("\n") + buffer.WriteString(" " + e.DeepDataMerge.LayoutConfig.BaseURL + "/" + string(templateData.CompleteURL) + "\n") + buffer.WriteString(" ") + xml.EscapeText(&buffer, []byte(templateData.Body)) + buffer.WriteString("\n") + buffer.WriteString(" \n") + } + + buffer.WriteString(" \n") + buffer.WriteString("\n") + outputFile, err := os.Create(helpers.SiteDataPath + "rendered/feed.xml") if err != nil { e.ErrorLogger.Fatal(err) diff --git a/pkg/helpers/helper.go b/pkg/helpers/helper.go index 50cf994..849e7b1 100644 --- a/pkg/helpers/helper.go +++ b/pkg/helpers/helper.go @@ -9,7 +9,7 @@ import ( const SiteDataPath string = "site/" -var version = "2.0.0" // use variable +var version = "2.1.0" // use variable type Helper struct { ErrorLogger *log.Logger diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index c4f21bc..1b69882 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -29,6 +29,7 @@ type LayoutConfig struct { SiteTitle string `yaml:"siteTitle"` SiteScripts []string `yaml:"siteScripts"` Author string `yaml:"author"` + Copyright string `yaml:"copyright"` ThemeURL string `yaml:"themeURL"` } diff --git a/site/layout/config.yml b/site/layout/config.yml index d22fb8c..3d099df 100644 --- a/site/layout/config.yml +++ b/site/layout/config.yml @@ -11,3 +11,4 @@ siteTitle: "anna-docs" siteScripts: author: anna themeURL: "/static/style.css" +copyright: "This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International." diff --git a/site/static/styles/feed.xsl b/site/static/styles/feed.xsl index 7b47381..fbcfebd 100644 --- a/site/static/styles/feed.xsl +++ b/site/static/styles/feed.xsl @@ -1,77 +1,82 @@ - + + + + <xsl:value-of select="/rss/channel/title"/> Web Feed - Web Feed • <xsl:value-of select="atom:feed/atom:title"/> - + - -
-
-

This is a web feed, also known as an RSS feed. Subscribe by copying the URL from the address bar into your newsreader app.

-
-
-
- -
-
+ +
+ +
+
+

+ + + + + + + + + + + + + + + + + + Web Feed Preview +

+

+

+ + + + + Visit Website → + +

Recent Items

- -
+ +
+

+ + + + + + +

+ + Published: + +
+
+ +
- - -

's Web Feed Preview

-

This RSS feed provides the latest posts from 's blog. - - - - - - Visit Website → - - -

- -

What is an RSS feed?

-

An RSS feed is a data format that contains the latest content from a website, blog, or podcast. You can use feeds to subscribe to websites and get the latest content in one place.

-
    -
  • Feeds put you in control. Unlike social media apps, there is no algorithm deciding what you see or read. You always get the latest content from the creators you care about.
  • -
  • Feed are private by design. No one owns web feeds, so no one is harvesting your personal information and profiting by selling it to advertisers.
  • -
  • Feeds are spam-proof. Had enough? Easy, just unsubscribe from the feed.
  • -
-

All you need to do to get started is to add the URL (web address) for this feed to a special app called a newsreader. Visit About Feeds to get started with newsreaders and subscribing. It’s free.

-
- - -
-

- - - - - - -

-

- -

- - Published: - -
-
-
\ No newline at end of file