Add html viewing
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user