Skip to content

Commit

Permalink
Merge pull request #125 from x-motemen/root-url
Browse files Browse the repository at this point in the history
define func *blogConfig.fetchRootURL
  • Loading branch information
Songmu authored Oct 29, 2023
2 parents fdfda0b + 4e65fff commit 40fe633
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 40fe633

Please sign in to comment.