new: add feeds to news page

This commit is contained in:
ngn 2024-08-23 14:11:48 +03:00
parent 52af211541
commit 60bff6356c
15 changed files with 204 additions and 45 deletions

View File

@ -6,4 +6,8 @@ website: */*.go *.go
format: format:
gofmt -s -w . gofmt -s -w .
.PHONY: format update:
go get -u
go mod tidy
.PHONY: format update

1
go.mod
View File

@ -6,6 +6,7 @@ require (
github.com/bigkevmcd/go-configparser v0.0.0-20240808124832-fc81059ea0bd github.com/bigkevmcd/go-configparser v0.0.0-20240808124832-fc81059ea0bd
github.com/gofiber/fiber/v2 v2.52.5 github.com/gofiber/fiber/v2 v2.52.5
github.com/gofiber/template/html/v2 v2.1.2 github.com/gofiber/template/html/v2 v2.1.2
github.com/gorilla/feeds v1.2.0
github.com/russross/blackfriday/v2 v2.1.0 github.com/russross/blackfriday/v2 v2.1.0
) )

12
go.sum
View File

@ -14,12 +14,14 @@ github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/feeds v1.2.0 h1:O6pBiXJ5JHhPvqy53NsjKOThq+dNFm8+DFrxBEdzSCc=
github.com/gorilla/feeds v1.2.0/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
@ -32,6 +34,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=

View File

@ -43,6 +43,9 @@ func main() {
app.Get("/download", routes.GET_Download) app.Get("/download", routes.GET_Download)
app.Get("/news", routes.GET_News) app.Get("/news", routes.GET_News)
app.Get("/news/feed.atom", routes.GET_NewsFeed)
app.Get("/news/feed.rss", routes.GET_NewsFeed)
app.Get("/news/feed.json", routes.GET_NewsFeed)
app.Get("/news/:id", routes.GET_New) app.Get("/news/:id", routes.GET_New)
app.Get("/wiki", routes.GET_Wiki) app.Get("/wiki", routes.GET_Wiki)

View File

@ -18,20 +18,27 @@
.downloads { .downloads {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
gap: 5px; gap: 8px;
}
.downloads a:first-child {
border-right: solid 1px var(--bright-third);
padding-right: 8px;
} }
.entry h1 { .entry h1 {
color: var(--bright-main); color: var(--bright-main);
font-weight: 900;
font-size: 20px; font-size: 20px;
} }
.entry a, .entry p { .entry a {
color: var(--bright-main); color: var(--bright-second);
font-size: 20px;
text-decoration: none; text-decoration: none;
font-weight: 100;
font-size: 20px;
} }
.entry a:hover { .entry a:hover {
color: var(--bright-second); text-decoration: underline;
} }

View File

@ -11,6 +11,42 @@ main {
} }
} }
.feed-menu {
display: flex;
justify-content: center;
flex-direction: row;
align-items: center;
margin-bottom: 6px;
color: white;
gap: 10px;
}
.feed-menu p {
color: var(--bright-main);
border-right: solid 1px var(--bright-third);
padding-right: 8px;
font-weight: 900;
font-size: 17px;
}
.feed-menu .feeds {
display: flex;
flex-direction: row;
align-items: center;
gap: 6px;
}
.feed-menu .feeds a {
font-weight: 100;
font-size: 16px;
color: var(--bright-second);
text-decoration: none;
}
.feed-menu .feeds a:hover {
text-decoration: underline;
}
.small { .small {
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@ -1,5 +1,17 @@
.subtext { .subtext {
display: flex;
flex-direction: row;
align-items: center;
margin: 12px 0 15px 0;
gap: 8px;
}
.subtext p {
font-size: 18px; font-size: 18px;
color: var(--bright-main); color: var(--bright-main);
margin: 5px 0 15px 0; }
.subtext p:first-child {
border-right: solid 1px var(--bright-third);
padding-right: 8px;
} }

View File

@ -1,18 +1,25 @@
package routes package routes
import ( import (
"fmt"
"path"
"sort" "sort"
"time"
"git.matterlinux.xyz/Matter/website/lib" "git.matterlinux.xyz/Matter/website/lib"
"git.matterlinux.xyz/Matter/website/log" "git.matterlinux.xyz/Matter/website/log"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gorilla/feeds"
) )
func GET_News(c *fiber.Ctx) error { func GetContent() ([]lib.Content, error) {
contents, err := lib.ListContent("news") var (
if err != nil { contents []lib.Content
log.Error("ListContent failed: %s", err.Error()) err error
return lib.RenderError(c, 500) )
if contents, err = lib.ListContent("news"); err != nil {
return nil, err
} }
sort.Slice(contents, func(i, j int) bool { sort.Slice(contents, func(i, j int) bool {
@ -31,6 +38,17 @@ func GET_News(c *fiber.Ctx) error {
return time1.After(time2) return time1.After(time2)
}) })
return contents, nil
}
func GET_News(c *fiber.Ctx) error {
contents, err := GetContent()
if err != nil {
log.Error("GetContent failed: %s", err.Error())
return lib.RenderError(c, 500)
}
return c.Render("news", fiber.Map{ return c.Render("news", fiber.Map{
"news": contents, "news": contents,
}) })
@ -67,3 +85,79 @@ func GET_New(c *fiber.Ctx) error {
return lib.RenderError(c, 404) return lib.RenderError(c, 404)
} }
func GET_NewsFeed(c *fiber.Ctx) error {
var (
feed_type string
feed *feeds.Feed
contents []lib.Content
res string
err error
)
feed_type = path.Base(c.Path())
if contents, err = GetContent(); err != nil {
log.Error("GetContent failed: %s", err.Error())
return lib.RenderError(c, 500)
}
feed = &feeds.Feed{
Title: "MatterLinux | News",
Link: &feeds.Link{Href: "https://matterlinux.xyz/news"}, // lets hardcode this for now
Description: "News regarding the MatterLinux project",
Created: time.Now(),
}
feed.Items = []*feeds.Item{}
for _, con := range contents {
parsed, err := time.Parse("02/01/06", con.Date)
if err != nil {
log.Error("Failed to parse post time (%s): %s", con.ID, err.Error())
return lib.RenderError(c, 500)
}
feed.Items = append(feed.Items, &feeds.Item{
Id: con.ID,
Title: con.Title,
Link: &feeds.Link{Href: fmt.Sprintf("https://matterlinux.xyz/news/%s", con.ID)},
Author: &feeds.Author{Name: con.Author},
Created: parsed,
Content: con.Md,
})
}
switch feed_type {
case "feed.atom":
if res, err = feed.ToAtom(); err != nil {
log.Error("Failed to convert feed to atom: %s", err.Error())
return lib.RenderError(c, 500)
}
c.Set("Content-Type", "application/atom+xml")
return c.Send([]byte(res))
case "feed.rss":
if res, err = feed.ToRss(); err != nil {
log.Error("Failed to convert feed to RSS: %s", err.Error())
return lib.RenderError(c, 500)
}
c.Set("Content-Type", "application/rss+xml")
return c.Send([]byte(res))
case "feed.json":
if res, err = feed.ToJSON(); err != nil {
log.Error("Failed to convert feed to JSON: %s", err.Error())
return lib.RenderError(c, 500)
}
c.Set("Content-Type", "application/feed+json")
return c.Send([]byte(res))
}
log.Error("Cannot handle the feed type: %s", feed_type)
return lib.RenderError(c, 404)
}

View File

@ -2,9 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>MatterLinux | Configs</title> <title>MatterLinux | Configs</title>
<meta charset="UTF-8"> {{template "parts/head" .}}
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">
<link href="/configs.css" rel="stylesheet"> <link href="/configs.css" rel="stylesheet">
<link href="/md.css" rel="stylesheet"> <link href="/md.css" rel="stylesheet">
</head> </head>

View File

@ -2,9 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>MatterLinux | Download</title> <title>MatterLinux | Download</title>
<meta charset="UTF-8"> {{template "parts/head" .}}
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">
<link href="/download.css" rel="stylesheet"> <link href="/download.css" rel="stylesheet">
<link href="/md.css" rel="stylesheet"> <link href="/md.css" rel="stylesheet">
</head> </head>
@ -12,26 +10,20 @@
{{template "parts/bar" .}} {{template "parts/bar" .}}
<main> <main>
<div class="md"> <div class="md">
<h1>Download MatterLinux</h1> <h1>Download MatterLinux {{.content.ID}}</h1>
</div> </div>
<div class="list"> <div class="list">
<div class="entry"> <div class="entry">
<h1>Version</h1> <h1>Archive</h1>
<h1>{{.content.ID}}</h1>
</div>
<div class="entry">
<h1>Release Archive</h1>
<div class="downloads"> <div class="downloads">
<a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.tar.gz">Download</a> <a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.tar.gz">Download</a>
<p>|</p>
<a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.tar.gz.sig">Signature</a> <a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.tar.gz.sig">Signature</a>
</div> </div>
</div> </div>
<div class="entry"> <div class="entry">
<h1>Release ISO</h1> <h1>ISO</h1>
<div class="downloads"> <div class="downloads">
<a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.iso">Download</a> <a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.iso">Download</a>
<p>|</p>
<a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.iso.sig">Signature</a> <a href="https://rel.matterlinux.xyz/{{.content.Title}}/matterlinux_{{.content.ID}}.iso.sig">Signature</a>
</div> </div>
</div> </div>

View File

@ -2,9 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>MatterLinux | Error</title> <title>MatterLinux | Error</title>
<meta charset="UTF-8"> {{template "parts/head" .}}
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">
<link href="/error.css" rel="stylesheet"> <link href="/error.css" rel="stylesheet">
</head> </head>
<body> <body>

View File

@ -2,9 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>MatterLinux</title> <title>MatterLinux</title>
<meta charset="UTF-8"> {{template "parts/head" .}}
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">
<link href="/md.css" rel="stylesheet"> <link href="/md.css" rel="stylesheet">
<link href="/index.css" rel="stylesheet"> <link href="/index.css" rel="stylesheet">
</head> </head>

View File

@ -2,14 +2,22 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>MatterLinux | News</title> <title>MatterLinux | News</title>
<meta charset="UTF-8"> {{template "parts/head" .}}
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">
<link href="/news.css" rel="stylesheet"> <link href="/news.css" rel="stylesheet">
<link rel="alternate" type="application/atom+xml" href="/news/feed.atom" title="Atom Feed">
<link rel="alternate" type="application/rss+xml" href="/news/feed.rss" title="RSS Feed">
</head> </head>
<body> <body>
{{template "parts/bar" .}} {{template "parts/bar" .}}
<main> <main>
<div class="feed-menu">
<p>Feeds</p>
<div class="feeds">
<a href="/news/feed.atom">Atom</a>
<a href="/news/feed.rss">RSS</a>
<a href="/news/feed.json">JSON</a>
</div>
</div>
{{range .news}} {{range .news}}
<a href="/news/{{.ID}}" class="small"> <a href="/news/{{.ID}}" class="small">
<h1>{{.Date}}</h1> <h1>{{.Date}}</h1>

View File

@ -0,0 +1,3 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">

View File

@ -2,9 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>MatterLinux | {{.title}}</title> <title>MatterLinux | {{.title}}</title>
<meta charset="UTF-8"> {{template "parts/head" .}}
<meta name="viewport" content="width=1200">
<link href="/global.css" rel="stylesheet">
<link href="/post.css" rel="stylesheet"> <link href="/post.css" rel="stylesheet">
<link href="/md.css" rel="stylesheet"> <link href="/md.css" rel="stylesheet">
</head> </head>
@ -14,7 +12,10 @@
<div class="md"> <div class="md">
<h1>{{.post.Title}}</h1> <h1>{{.post.Title}}</h1>
</div> </div>
<p class="subtext">{{.post.Date}} | by {{.post.Author}}</p> <div class="subtext">
<p class="date">{{.post.Date}}</p>
<p class="author">by {{.post.Author}}</p>
</div>
<div class="md"> <div class="md">
{{.post.HTML}} {{.post.HTML}}
</div> </div>