<commit_before>package gold

import (
	"errors"
	"fmt"
	"strings"
	"time"
)

const (
	TimeFormat = "January 2, 2006"
	readMore   = "<!--readmore-->"
)

type Articles []*Article
type Article struct {
	Date     time.Time
	Edit     time.Time
	Title    string
	Slug     string
	Body     string
	Tags     Tags
	Enabled  bool
	Author   string
	Comments Comments
}

type YearMap map[int]Articles
type MonthMap map[int]Articles

func (a *Article) makeSlug() {
	r := strings.NewReplacer(" ", "-")
	a.Slug = r.Replace(strings.TrimSpace(a.Title))
}

func (a *Article) Publish() {
	a.Date = time.Now()
	a.Enabled = true
}

func (a *Article) Suppress() {
	a.Enabled = false
}

func (a *Article) AddComment(c *Comment) {
	a.Comments.Add(c)
}

func (a Articles) Len() int           { return len(a) }
func (a Articles) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Articles) Less(i, j int) bool { return a[i].Date.Before(a[j].Date) }

func (a *Articles) Add(article *Article) error {
	article.Date = time.Now()
	if article.Slug == "" {
		article.makeSlug()
	}
	_, err := a.Find(article.Slug)
	if err == nil {
		return errors.New("duplicate slug " + article.Slug)
	}
	*a = append(*a, article)
	return nil
}

func (a *Articles) Update(article *Article) error {
	article.Edit = time.Now()
	if article.Slug == "" {
		article.makeSlug()
	}
	i, err := a.locate(article.Slug)
	if err != nil {
		return a.Add(article)
	}
	(*a)[i] = article
	return nil
}

func (a Articles) locate(slug string) (int, error) {
	for i, ar := range a {
		if ar.Slug == slug {
			return i, nil
		}
	}
	return 0, errors.New("not found " + slug)
}

func (a Articles) Find(slug string) (*Article, error) {
	i, err := a.locate(slug)
	if err != nil {
		return nil, err
	}
	return a[i], nil
}

func (a Articles) Page(page, app int) (Articles, int, int) {<commit_msg>preserve date<commit_after>package gold

import (
	"errors"
	"fmt"
	"strings"
	"time"
)

const (
	TimeFormat = "January 2, 2006"
	readMore   = "<!--readmore-->"
)

type Articles []*Article
type Article struct {
	Date     time.Time
	Edit     time.Time
	Title    string
	Slug     string
	Body     string
	Tags     Tags
	Enabled  bool
	Author   string
	Comments Comments
}

type YearMap map[int]Articles
type MonthMap map[int]Articles

func (a *Article) makeSlug() {
	r := strings.NewReplacer(" ", "-")
	a.Slug = r.Replace(strings.TrimSpace(a.Title))
}

func (a *Article) Publish() {
	a.Date = time.Now()
	a.Enabled = true
}

func (a *Article) Suppress() {
	a.Enabled = false
}

func (a *Article) AddComment(c *Comment) {
	a.Comments.Add(c)
}

func (a Articles) Len() int           { return len(a) }
func (a Articles) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Articles) Less(i, j int) bool { return a[i].Date.Before(a[j].Date) }

func (a *Articles) Add(article *Article) error {
	article.Date = time.Now()
	if article.Slug == "" {
		article.makeSlug()
	}
	_, err := a.Find(article.Slug)
	if err == nil {
		return errors.New("duplicate slug " + article.Slug)
	}
	*a = append(*a, article)
	return nil
}

func (a *Articles) Update(article *Article) error {
	article.Edit = time.Now()
	if article.Slug == "" {
		article.makeSlug()
	}
	i, err := a.locate(article.Slug)
	if err != nil {
		return a.Add(article)
	}
	article.Date = (*a)[i].Date
	(*a)[i] = article
	return nil
}

func (a Articles) locate(slug string) (int, error) {
	for i, ar := range a {
		if ar.Slug == slug {
			return i, nil
		}
	}
	return 0, errors.New("not found " + slug)
}

func (a Articles) Find(slug string) (*Article, error) {
	i, err := a.locate(slug)
	if err != nil {
		return nil, err
	}
	return a[i], nil
}

func (a Articles) Page(page, app int) (Articles, int, int) {
{'fraction_non_alphanumeric': 0.1626325809083492, 'fraction_numerical': 0.003263530051672559, 'mean_word_length': 3.2668213457076565, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3246685', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1443, 'n_words': 397}