From 72f3abe3ad474c9ab0c4611b115d6024468ed1f7 Mon Sep 17 00:00:00 2001 From: Gwyn Date: Sun, 28 Apr 2024 17:40:23 -0600 Subject: [PATCH] Renames page_parser and AndrewPage to page. Just simplifying things. --- page_parser.go => page.go | 22 +++++++++++----------- page_parser_test.go => page_test.go | 0 2 files changed, 11 insertions(+), 11 deletions(-) rename page_parser.go => page.go (86%) rename page_parser_test.go => page_test.go (100%) diff --git a/page_parser.go b/page.go similarity index 86% rename from page_parser.go rename to page.go index a1bb5fd..d8ff4e9 100644 --- a/page_parser.go +++ b/page.go @@ -17,11 +17,11 @@ const ( indexIdentifier = "index.html" ) -// AndrewPage tracks the content of a specific file and various pieces of metadata about it. -// The AndrewPage makes creating links and serving content convenient, as it lets me offload +// Page tracks the content of a specific file and various pieces of metadata about it. +// The Page makes creating links and serving content convenient, as it lets me offload // the parsing of any elements into a constructor, so that when I need to present those // elements to an end-user they're easy for me to reason about. -type AndrewPage struct { +type Page struct { // Page title Title string // According to https://datatracker.ietf.org/doc/html/rfc1738#section-3.1, the subsection of a @@ -32,32 +32,32 @@ type AndrewPage struct { // NewPage creates a Page from a URL by reading the corresponding file from the // AndrewServer's SiteFiles. -func NewPage(server Server, pageUrl string) (AndrewPage, error) { +func NewPage(server Server, pageUrl string) (Page, error) { pageContent, err := fs.ReadFile(server.SiteFiles, pageUrl) if err != nil { - return AndrewPage{}, err + return Page{}, err } // The fs.FS documentation notes that paths should not start with a leading slash. pagePath := strings.TrimPrefix(pageUrl, "/") pageTitle, err := getTitle(pagePath, pageContent) if err != nil { - return AndrewPage{}, err + return Page{}, err } if strings.Contains(pageUrl, indexIdentifier) { pageContent, err = buildAndrewIndexBody(server, pageUrl, pageContent) if err != nil { - return AndrewPage{}, err + return Page{}, err } } - return AndrewPage{Content: string(pageContent), UrlPath: pageUrl, Title: pageTitle}, nil + return Page{Content: string(pageContent), UrlPath: pageUrl, Title: pageTitle}, nil } // SetUrlPath updates the UrlPath on a pre-existing AndrewPage. -func (a AndrewPage) SetUrlPath(urlPath string) AndrewPage { - return AndrewPage{Title: a.Title, Content: a.Content, UrlPath: urlPath} +func (a Page) SetUrlPath(urlPath string) Page { + return Page{Title: a.Title, Content: a.Content, UrlPath: urlPath} } // buildAndrewIndexBody receives the path to a file, currently normally an index file. @@ -107,7 +107,7 @@ func buildAndrewIndexBody(server Server, startingPageUrl string, pageContent []b } // buildAndrewIndexLink encapsulates the format of the link -func buildAndrewIndexLink(page AndrewPage, cssIdNumber int) []byte { +func buildAndrewIndexLink(page Page, cssIdNumber int) []byte { link := fmt.Sprintf("%s", fmt.Sprint(cssIdNumber), page.UrlPath, page.Title) b := []byte(link) return b diff --git a/page_parser_test.go b/page_test.go similarity index 100% rename from page_parser_test.go rename to page_test.go