2024-01-06 20:20:58 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/russross/blackfriday/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RenderError(c *fiber.Ctx, code int) error{
|
|
|
|
var msg string = "Server Error"
|
|
|
|
c.Status(code)
|
|
|
|
|
|
|
|
switch code {
|
|
|
|
case 404:
|
|
|
|
msg = "Not Found"
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.Render("error", fiber.Map{
|
|
|
|
"msg": msg,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TimeFromString(date string) (time.Time, error) {
|
|
|
|
res, err := time.Parse("02/01/06", date)
|
|
|
|
if err == nil {
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
return time.Now(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseMarkdown(md string) string {
|
|
|
|
ext := blackfriday.FencedCode
|
|
|
|
ext |= blackfriday.BackslashLineBreak
|
|
|
|
ext |= blackfriday.Strikethrough
|
|
|
|
ext |= blackfriday.Tables
|
2024-01-18 17:01:30 +00:00
|
|
|
ext |= blackfriday.NoEmptyLineBeforeBlock
|
2024-01-06 20:20:58 +00:00
|
|
|
|
|
|
|
return string(blackfriday.Run([]byte(md), blackfriday.WithExtensions(ext)))
|
|
|
|
}
|