Skip to content

Commit

Permalink
feat: style atom feeds
Browse files Browse the repository at this point in the history
closes: #95
misc: update docs, prompt user before sitedir bootstrap
  • Loading branch information
polarhive committed Apr 10, 2024
1 parent 7520128 commit 7fac334
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 40 deletions.
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,28 @@ A static site generator in go

Inspired by [Hugo](https://gohugo.io) and [Saaru](https://github.com/anirudhRowjee/saaru), this static site generator aims to take performance to the next level with parallel rendering, live reload and so much more, all in Go.

> Pronounced: `/ɐnːɐ/` which means rice in Kannada 🍚
Pronounced: `/ɐnːɐ/` which means rice 🍚 in Kannada

This project is a part of the ACM PESU-ECC's yearly [AIEP](https://acmpesuecc.github.io/aiep) program, and is maintained by [Adhesh Athrey](https://github.com/DedLad), [Nathan Paul](https://github.com/polarhive), [Anirudh Sudhir](https://github.com/anirudhsudhir), and [Aditya Hegde](https://github.com/bwaklog)
> This project is a part of the ACM PESU-ECC's yearly [AIEP](https://acmpesuecc.github.io/aiep) program, and is maintained by [Adhesh Athrey](https://github.com/DedLad), [Nathan Paul](https://github.com/polarhive), [Anirudh Sudhir](https://github.com/anirudhsudhir), and [Aditya Hegde](https://github.com/bwaklog)
---

## Install
## Get Started

```sh
go run github.com/acmpesuecc/[email protected]
```
> If you don't have a site dir with the pre-requisite layout template; anna proceeds to fetch the default site dir from our GitHub repository
Alternatively, clone our repository to build the latest version of anna:

```sh
git clone github.com/acmpesuecc/anna --depth=1; cd anna
go run .
```

### Detailed documentation of our SSG can be found [here](https://anna-docs.netlify.app/)
## Contributing to Anna

---
Detailed documentation for our SSG can be found: [here](https://anna-docs.netlify.app/)

## Flags
If you have git installed, clone our repository and build against the latest commit

```sh
git clone github.com/acmpesuecc/anna; cd anna
go build
```
```text
Usage:
anna [flags]
Expand Down
7 changes: 4 additions & 3 deletions pkg/engine/anna_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func (e *Engine) GenerateSitemap(outFilePath string) {
func (e *Engine) GenerateFeed() {
var buffer bytes.Buffer
buffer.WriteString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
buffer.WriteString("<?xml-stylesheet href=\"/static/styles/feed.xsl\" type=\"text/xsl\"?>\n")
buffer.WriteString("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n")
buffer.WriteString(" <title>" + e.LayoutConfig.SiteTitle + "</title>\n")
buffer.WriteString(" <link href=\"" + e.LayoutConfig.BaseURL + "/" + "\" rel=\"self\"/>\n")
Expand All @@ -162,18 +163,18 @@ func (e *Engine) GenerateFeed() {
// iterate over parsed markdown files that are non-draft posts
for _, templateData := range e.Templates {
if !templateData.Frontmatter.Draft {
buffer.WriteString(" <entry>\n")
buffer.WriteString("<entry>\n")
buffer.WriteString(" <title>" + templateData.Frontmatter.Title + "</title>\n")
buffer.WriteString(" <link href=\"" + e.LayoutConfig.BaseURL + "/posts/" + templateData.FilenameWithoutExtension + ".html\"/>\n")
buffer.WriteString(" <id>" + e.LayoutConfig.BaseURL + "/" + templateData.FilenameWithoutExtension + ".html</id>\n")
buffer.WriteString(" <id>" + e.LayoutConfig.BaseURL + "/posts/" + templateData.FilenameWithoutExtension + ".html</id>\n")
buffer.WriteString(" <updated>" + time.Unix(templateData.Date, 0).Format(time.RFC3339) + "</updated>\n")
buffer.WriteString(" <content type=\"html\"><![CDATA[" + string(templateData.Body) + "]]></content>\n")
buffer.WriteString(" </entry>\n")
}
}

buffer.WriteString("</feed>\n")
outputFile, err := os.Create(helpers.SiteDataPath + "rendered/feed.atom")
outputFile, err := os.Create(helpers.SiteDataPath + "rendered/feed.xml")
if err != nil {
e.ErrorLogger.Fatal(err)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/helpers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func (h *Helper) CreateRenderedDir(fileOutPath string) {
}

func (h *Helper) Bootstrap() {
fmt.Println("Are you sure you want to proceed with the bootstrap process? (y/n)")
var confirm string
fmt.Scanln(&confirm)
if confirm != "y" {
fmt.Println("Bootstrap process cancelled.")
return
}
log.Println("Downloading base theme")
url := "https://github.com/acmpesuecc/anna/archive/refs/heads/main.zip"
output, err := os.Create("anna-repo.zip")
Expand Down
42 changes: 22 additions & 20 deletions site/content/docs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
date: 2024-04-10
title: Anna Documentation
---

Expand All @@ -20,12 +21,12 @@ Pronounced: `/ɐnːɐ/` which means rice in Kannada 🍚

This Project is a part of the ACM PESU-ECC's yearly [AIEP](https://acmpesuecc.github.io/aiep) program, and is maintained by [Adhesh Athrey](https://github.com/DedLad), [Nathan Paul](https://github.com/polarhive), [Anirudh Sudhir](https://github.com/anirudhsudhir), and [Aditya Hegde](https://github.com/bwaklog)

---
## Directory structure

The ssg currently requires the following directory structure

```text
/anna
├── /cmd
├── /pkg
Expand Down Expand Up @@ -134,42 +135,43 @@ navbar:
- posts

baseURL: http://localhost:8000/
# Replace this with the actual canonical-url of your site.

# Replace this with the actual canonical-url of your site
# baseURL tells search-engines (SEO), web-crawlers (robots.txt) so people can discover your site on the internet.
# It's also embeded in your sitemap / atom feed and can be used to change metadata about your site.

siteTitle: anna
siteScripts:
author: Anna
```
## Install
Once you have a directory structure, install `anna` using:
---
## Run locally
```sh
go install github.com/acmpesuecc/anna@latest
go run github.com/acmpesuecc/anna@v1.0.0-alpha
```
> If you don't have a site dir with the pre-requisite layout template; anna proceeds to fetch the default site dir from our GitHub repository
Or if you have git installed, clone our repository:
## Contributing to Anna

```sh
git clone github.com/acmpesuecc/anna --depth=1
cd anna
go run .
```
Detailed documentation for our SSG can be found: [here](https://anna-docs.netlify.app/)

## Flags
If you have git installed, clone our repository and build against the latest commit

```sh
git clone github.com/acmpesuecc/anna; cd anna
go build
```
```text
Usage:
anna [flags]
Flags:
-a, --addr stringwhich sip address to serve rendered content to (default "8000")
-d, --draft renders draft posts
-h, --help help for ssg
-s, --serve serve the rendered content
-v, --validate-html validate semantic HTML
-a, --addr string ip address to serve rendered content to (default "8000")
-d, --draft renders draft posts
-h, --help help for anna
-l, --layout validates html layouts
-p, --prof enable profiling
-s, --serve serve the rendered content
-v, --version prints current version number
-w, --webconsole wizard to setup anna
```
2 changes: 1 addition & 1 deletion site/content/posts/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: benchmark
template: post.jinja
author: John Doe
date: 2024-02-23
date: 2024-01-01
categories:
- Technology
- Programming
Expand Down
2 changes: 1 addition & 1 deletion site/layout/partials/head.layout
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script src="https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/highlight.min.js"></script>
<script defer src="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.css" />
<link rel="alternate" type="application/atom+xml" title="feed" href="/feed.atom" />
<link rel="alternate" type="application/atom+xml" title="feed" href="/feed.xml" />

{{range .Frontmatter.JSFiles}}
<script src="/script/{{.}}" defer></script>
Expand Down
2 changes: 1 addition & 1 deletion site/static/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"bench.md":{"CompleteURL":"posts/bench.html","FilenameWithoutExtension":"bench","Frontmatter":{"Title":"benchmark","Date":"2024-02-23","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":"","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"]}}
{"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"]}}
77 changes: 77 additions & 0 deletions site/static/styles/feed.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
exclude-result-prefixes="atom"
>
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>Web Feed • <xsl:value-of select="atom:feed/atom:title"/></title>
<style type="text/css">
body{max-width:768px;margin:0 auto;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:16px;line-height:1.5em}section{margin:30px 15px}h1{font-size:2em;margin:.67em 0;line-height:1.125em}h2{border-bottom:1px solid #eaecef;padding-bottom:.3em}.alert{background:#fff5b1;padding:4px 12px;margin:0 -12px}a{text-decoration:none}.entry h3{margin-bottom:0}.entry p{margin:4px 0}
</style>
</head>
<body>
<section>
<div class="alert">
<p><strong>This is a web feed</strong>, also known as an RSS feed. <strong>Subscribe</strong> by copying the URL from the address bar into your newsreader app.</p>
</div>
</section>
<section>
<xsl:apply-templates select="atom:feed" />
</section>
<section>
<h2>Recent Items</h2>
<xsl:apply-templates select="atom:feed/atom:entry" />
</section>
</body>
</html>
</xsl:template>

<xsl:template match="atom:feed">
<h1><xsl:value-of select="atom:title"/>'s Web Feed Preview</h1>
<p>This RSS feed provides the latest posts from <xsl:value-of select="atom:title"/>'s blog.

<a class="head_link" target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="atom:link[@rel='alternate']/@href"/>
</xsl:attribute>
Visit Website &#x2192;
</a>

</p>

<h2>What is an RSS feed?</h2>
<p>An RSS feed is a data format that contains the latest content from a website, blog, or podcast. You can use feeds to <strong>subscribe</strong> to websites and get the <strong>latest content in one place</strong>.</p>
<ul>
<li><strong>Feeds put you in control.</strong> 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.</li>
<li><strong>Feed are private by design.</strong> No one owns web feeds, so no one is harvesting your personal information and profiting by selling it to advertisers.</li>
<li><strong>Feeds are spam-proof.</strong> Had enough? Easy, just unsubscribe from the feed.</li>
</ul>
<p>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 <a href="https://aboutfeeds.com/">About Feeds</a> to get started with newsreaders and subscribing. It’s free. </p>
</xsl:template>

<xsl:template match="atom:entry">
<div class="entry">
<h3>
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="atom:id"/>
</xsl:attribute>
<xsl:value-of select="atom:title"/>
</a>
</h3>
<p>
<xsl:value-of select="atom:summary" disable-output-escaping="yes" />
</p>
<small>
Published: <xsl:value-of select="atom:updated" />
</small>
</div>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 7fac334

Please sign in to comment.