diff --git a/pkg/thread/io.go b/pkg/thread/io.go index 4744dbf..aeb996e 100644 --- a/pkg/thread/io.go +++ b/pkg/thread/io.go @@ -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) } @@ -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 @@ -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 diff --git a/pkg/thread/template.go b/pkg/thread/template.go index 9ed6ace..d07baa6 100644 --- a/pkg/thread/template.go +++ b/pkg/thread/template.go @@ -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{ @@ -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 } @@ -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 = `