Skip to content

Commit

Permalink
naming consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
dkaslovsky committed Jan 29, 2023
1 parent 40b1b1a commit 4ad18c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions pkg/thread/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (th *Thread) ToJSON() error {
}

// ToHTML generates and saves an HTML file from a thread using default or provided template and CSS files
func (th *Thread) ToHTML(templateFile string, cssFile string) error {
htmlTemplate, err := loadTemplate(th.Dir, templateFile, cssFile)
func (th *Thread) ToHTML(templateFileName string, cssFileName string) error {
htmlTemplate, err := loadTemplate(th.Dir, templateFileName, cssFileName)
if err != nil {
return fmt.Errorf("failed to load template: %w", err)
}
Expand Down Expand Up @@ -102,9 +102,9 @@ func (th *Thread) DownloadAttachments() error {
return nil
}

func loadHTMLTemplateFile(threadDir *Directory, templateFile string) (string, error) {
if templateFile != "" {
return readFile(templateFile)
func loadHTMLTemplateFile(threadDir *Directory, templateFileName string) (string, error) {
if templateFileName != "" {
return readFile(templateFileName)
}

// Try to load default template from file
Expand All @@ -115,9 +115,9 @@ func loadHTMLTemplateFile(threadDir *Directory, templateFile string) (string, er
return "", nil
}

func getCSSFile(threadDir *Directory, cssFile string) string {
if cssFile != "" {
return filepath.Clean(cssFile)
func getCSSFilePath(threadDir *Directory, cssFileName string) string {
if cssFileName != "" {
return cssFileName
}

// Try to load default CSS file
Expand Down
14 changes: 7 additions & 7 deletions pkg/thread/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ func NewTemplateThread(th *Thread) TemplateThread {
for i, tweet := range th.Tweets {
attachments := []TemplateAttachment{}
for _, attachment := range tweet.Attachments {
attachmentFile := attachment.Name(tweet.ID)
attachmentFileName := attachment.Name(tweet.ID)

// Skip attachment if not downloaded
if _, exists := attachmentDir.SubDir(attachmentFile); !exists {
if _, exists := attachmentDir.SubDir(attachmentFileName); !exists {
continue
}

attachments = append(attachments, TemplateAttachment{
Path: attachmentFile,
Ext: filepath.Ext(attachmentFile),
Path: attachmentFileName,
Ext: filepath.Ext(attachmentFileName),
})
}
tweets = append(tweets, TemplateTweet{
Expand Down Expand Up @@ -82,8 +82,8 @@ func (a TemplateAttachment) IsVideo() bool {
return valid
}

func loadTemplate(threadDir *Directory, templateFile string, cssFile string) (string, error) {
html, err := loadHTMLTemplateFile(threadDir, templateFile)
func loadTemplate(threadDir *Directory, templateFileName string, cssFileName string) (string, error) {
html, err := loadHTMLTemplateFile(threadDir, templateFileName)
if err != nil {
return "", err
}
Expand All @@ -96,7 +96,7 @@ func loadTemplate(threadDir *Directory, templateFile string, cssFile string) (st
return html, nil
}

return fmt.Sprintf(html, getCSSFile(threadDir, cssFile)), nil
return fmt.Sprintf(html, filepath.Clean(getCSSFilePath(threadDir, cssFileName))), nil
}

const defaultTemplate = `
Expand Down

0 comments on commit 4ad18c8

Please sign in to comment.