Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define func *blogConfig.fetchRootURL #125

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (b *broker) FetchRemoteEntries(published, drafts bool) ([]*entry, error) {
}
return nil, err
}
if b.rootURL != "" {
if l := feed.Links.Find("alternate"); l != nil {
b.rootURL = l.Href
}
}

for _, ae := range feed.Entries {
e, err := entryFromAtom(&ae)
Expand Down
17 changes: 17 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type blogConfig struct {
OmitDomain *bool `yaml:"omit_domain"`
Owner string `yaml:"owner"`
local bool
rootURL string
}

func (bc *blogConfig) localRoot() string {
Expand All @@ -55,6 +56,22 @@ func (bc *blogConfig) localRoot() string {
return filepath.Join(paths...)
}

func (bc *blogConfig) fetchRootURL() string {
if bc.rootURL != "" {
return bc.rootURL
}
b := newBroker(bc)
u := entryEndPointUrl(bc)
feed, err := b.Client.GetFeed(u)
if err != nil {
return ""
}
if l := feed.Links.Find("alternate"); l != nil {
b.rootURL = l.Href
}
return b.rootURL
}

func loadConfig(r io.Reader, fpath string) (*config, error) {
bytes, err := io.ReadAll(r)
if err != nil {
Expand Down
Loading