Skip to content

Commit

Permalink
Renames page_parser and AndrewPage to page. Just simplifying things.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynforthewyn committed Apr 28, 2024
1 parent c0d7ff0 commit 72f3abe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions page_parser.go → page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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("<a class=\"andrewindexbodylink\" id=\"andrewindexbodylink%s\" href=\"%s\">%s</a>", fmt.Sprint(cssIdNumber), page.UrlPath, page.Title)
b := []byte(link)
return b
Expand Down
File renamed without changes.

0 comments on commit 72f3abe

Please sign in to comment.