|
|
|
@ -3,16 +3,35 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"math/rand"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
MetaKV = regexp.MustCompile(`(\w+)::\s+(.*)`)
|
|
|
|
|
MetaKV = regexp.MustCompile(`(\w+)::\s+(.*)`)
|
|
|
|
|
niceDateParseRE = regexp.MustCompile(`^(\d{1,2})_([a-z]+)_(\d{4})$`)
|
|
|
|
|
ParseFailed = errors.New("parse failed")
|
|
|
|
|
Months = []string{
|
|
|
|
|
"",
|
|
|
|
|
"januari",
|
|
|
|
|
"februari",
|
|
|
|
|
"maart",
|
|
|
|
|
"april",
|
|
|
|
|
"mei",
|
|
|
|
|
"juni",
|
|
|
|
|
"juli",
|
|
|
|
|
"augustus",
|
|
|
|
|
"september",
|
|
|
|
|
"oktober",
|
|
|
|
|
"november",
|
|
|
|
|
"december",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ParsedLink struct {
|
|
|
|
@ -103,40 +122,10 @@ func todayPage() string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func formatDateTitle(date time.Time) string {
|
|
|
|
|
months := []string{
|
|
|
|
|
"",
|
|
|
|
|
"januari",
|
|
|
|
|
"februari",
|
|
|
|
|
"maart",
|
|
|
|
|
"april",
|
|
|
|
|
"mei",
|
|
|
|
|
"juni",
|
|
|
|
|
"juli",
|
|
|
|
|
"augustus",
|
|
|
|
|
"september",
|
|
|
|
|
"oktober",
|
|
|
|
|
"november",
|
|
|
|
|
"december",
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%d %s %d", date.Day(), months[date.Month()], date.Year())
|
|
|
|
|
return fmt.Sprintf("%d %s %d", date.Day(), Months[date.Month()], date.Year())
|
|
|
|
|
}
|
|
|
|
|
func formatDatePageName(date time.Time) string {
|
|
|
|
|
months := []string{
|
|
|
|
|
"",
|
|
|
|
|
"januari",
|
|
|
|
|
"februari",
|
|
|
|
|
"maart",
|
|
|
|
|
"april",
|
|
|
|
|
"mei",
|
|
|
|
|
"juni",
|
|
|
|
|
"juli",
|
|
|
|
|
"augustus",
|
|
|
|
|
"september",
|
|
|
|
|
"oktober",
|
|
|
|
|
"november",
|
|
|
|
|
"december",
|
|
|
|
|
}
|
|
|
|
|
return fmt.Sprintf("%d_%s_%d", date.Day(), months[date.Month()], date.Year())
|
|
|
|
|
return fmt.Sprintf("%d_%s_%d", date.Day(), Months[date.Month()], date.Year())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PageTitle(pageText string) (string, error) {
|
|
|
|
@ -158,3 +147,31 @@ func PageTitle(pageText string) (string, error) {
|
|
|
|
|
}
|
|
|
|
|
return "", fmt.Errorf("no meta title found in page text")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseMonth(month string) (time.Month, error) {
|
|
|
|
|
for i, m := range Months {
|
|
|
|
|
if m == month {
|
|
|
|
|
return time.Month(i), nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return time.Month(0), fmt.Errorf("parseMonth: %q is not a recognized month", month)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ParseDatePageName(name string) (time.Time, error) {
|
|
|
|
|
if matches := niceDateParseRE.FindStringSubmatch(name); matches != nil {
|
|
|
|
|
day, err := strconv.Atoi(matches[1])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return time.Time{}, fmt.Errorf("%q: %s: %w", name, err, ParseFailed)
|
|
|
|
|
}
|
|
|
|
|
month, err := parseMonth(matches[2])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return time.Time{}, fmt.Errorf("%q: %s: %w", name, err, ParseFailed)
|
|
|
|
|
}
|
|
|
|
|
year, err := strconv.Atoi(matches[3])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return time.Time{}, fmt.Errorf("%q: %s: %w", name, err, ParseFailed)
|
|
|
|
|
}
|
|
|
|
|
return time.Date(year, month, day, 0, 0, 0, 0, time.Local), nil
|
|
|
|
|
}
|
|
|
|
|
return time.Time{}, fmt.Errorf("%q: invalid syntax: %w", name, ParseFailed)
|
|
|
|
|
}
|
|
|
|
|