Add html viewing

This commit is contained in:
Senad Uka
2023-08-05 10:58:20 +02:00
parent 517486689e
commit 39a0d3fe00
30 changed files with 11537 additions and 1 deletions

View File

@@ -23,6 +23,18 @@ func (l *Link) GemtextArchiveMonthLink() string {
return fmt.Sprintf("=> /y/%d/m/%d/ %d-%d\n", l.Year, l.Month, l.Year, l.Month)
}
func (l *Link) HTMLLink() string {
return fmt.Sprintf("<a href=\"/p/%d/%s\">%d-%d-%d - %s</a><br>\n", l.ID, l.TitleSlug, l.Year, l.Month, l.Day, l.Title)
}
func (l *Link) HTMLArchiveLink() string {
return fmt.Sprintf("<a href=\"/y/%d/\">Godina %d.</a><br>\n", l.Year, l.Year)
}
func (l *Link) HTMLArchiveMonthLink() string {
return fmt.Sprintf("<a href=\"/y/%d/m/%d/\">%d-%d</a><br>\n", l.Year, l.Month, l.Year, l.Month)
}
func GetRecentLinks() ([]Link, error) {
db := GetDB()
links := []Link{}
@@ -37,7 +49,7 @@ func GetLinksByMonth(year, month int) ([]Link, string, error) {
db := GetDB()
links := []Link{}
err := db.Select(&links, "SELECT id, title_slug, year, month, day, post_title FROM posts WHERE year = ? and month = ? ORDER BY date desc", year, month)
err := db.Select(&links, "SELECT id, title_slug, year, month, day, post_title FROM posts WHERE year = ? and month = ? ORDER BY date desc", year, month)
if err != nil {
return nil, "", err
}

View File

@@ -3,6 +3,8 @@ package database
import (
"database/sql"
"fmt"
"github.com/russross/blackfriday/v2"
)
type Post struct {
@@ -20,6 +22,11 @@ func (p *Post) GemtextPage() string {
return fmt.Sprintf("# %s\n\n", p.Title) + p.GemtextContent.String
}
func (p *Post) HTMLPage() string {
extensions := blackfriday.CommonExtensions | blackfriday.HardLineBreak
return fmt.Sprintf("<h1>%s</h1>\n%s", p.Title, blackfriday.Run([]byte(p.MarkdownContent), blackfriday.WithExtensions(extensions)))
}
func GetPost(id int) (*Post, error) {
db := GetDB()
post := &Post{}