1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-19 19:25:24 +00:00

Refine post prefix logic

Improved for hosted users and feeds with titles and authors.
This commit is contained in:
makeworld 2020-11-19 12:50:49 -05:00
parent fb8af885ab
commit 8ffc0ca29c
5 changed files with 54 additions and 17 deletions

View File

@ -1,6 +1,7 @@
# Notes
## Feeds (temp)
- Feed page doesn't update automatically if you add a feed by bottom bar URL while already on the feed page
- TODO: remove all logger lines
## Issues

View File

@ -127,8 +127,9 @@ Features in *italics* are in the master branch, but not in the latest release.
- Manage and browse them
- Similar to [Kristall](https://github.com/MasterQ32/kristall)
- https://lists.orbitalfox.eu/archives/gemini/2020/001400.html
- [x] *Subscribe to RSS and Atom feeds and display them*
- Subscribing to page changes, similar to how Spacewalk works, will also be supported
- [x] Subscribe to feeds and display them
- Tracking page changes is also supported
- RSS, Atom, and [JSON Feeds](https://jsonfeed.org/) are all supported
- [ ] Stream support
- [ ] Table of contents for pages
- [ ] History browser

View File

@ -70,12 +70,12 @@ func Feeds(t *tab) {
feedPageRaw += fmt.Sprintf("\n## %s\n\n", curDay.Format("Jan 02, 2006"))
}
if entry.Title == "" || entry.Title == "/" {
// Just put author
// Just put author/title
// Mainly used for when you're tracking the root domain of a site
feedPageRaw += fmt.Sprintf("=>%s %s\n", entry.URL, entry.Author)
feedPageRaw += fmt.Sprintf("=>%s %s\n", entry.URL, entry.Prefix)
} else {
// Include title and dash
feedPageRaw += fmt.Sprintf("=>%s %s - %s\n", entry.URL, entry.Author, entry.Title)
feedPageRaw += fmt.Sprintf("=>%s %s - %s\n", entry.URL, entry.Prefix, entry.Title)
}
}

View File

@ -317,7 +317,7 @@ func updateAll() {
return
}
numWorkers := viper.GetInt("feed.workers")
numWorkers := viper.GetInt("feeds.workers")
if numWorkers < 1 {
numWorkers = 1
}
@ -390,19 +390,39 @@ func GetPageEntries() *PageEntries {
pub = time.Now()
}
var author string
if feed.Author == nil {
if item.Author == nil {
author = "[author unknown]"
// Prefer using the feed title over anything else.
// Many feeds in Gemini only have this due to gemfeed's default settings.
prefix := feed.Title
if prefix == "" {
// feed.Title was empty
if feed.Author != nil {
// Prefer using the feed author over the item author
prefix = feed.Author.Name
} else {
author = item.Author.Name
if item.Author != nil {
prefix = item.Author.Name
} else {
prefix = "[author unknown]"
}
}
} else {
author = feed.Author.Name
// There's already a title, so add the author (if exists) to
// the end of the title in parentheses.
// Don't add the author if it's the same as the title.
if feed.Author != nil && feed.Author.Name != prefix {
// Prefer using the feed author over the item author
prefix += " (" + feed.Author.Name + ")"
} else {
if item.Author != nil && item.Author.Name != prefix {
prefix += " (" + item.Author.Name + ")"
}
}
}
pe.Entries = append(pe.Entries, &PageEntry{
Author: author,
Prefix: prefix,
Title: item.Title,
URL: item.Link,
Published: pub,
@ -414,11 +434,26 @@ func GetPageEntries() *PageEntries {
parsed, _ := urlPkg.Parse(url)
// Path is title
// "/users/" is removed for aesthetics when tracking hosted users
title := strings.TrimPrefix(parsed.Path, "/users/")
title := parsed.Path
if strings.HasPrefix(title, "/~") {
// A user dir
title = title[2:] // Remove beginning slash and tilde
// Remove trailing slash if the root of a user dir is being tracked
if strings.Count(title, "/") <= 1 && title[len(title)-1] == '/' {
title = title[:len(title)-1]
}
} else if strings.HasPrefix(title, "/users/") {
// "/users/" is removed for aesthetics when tracking hosted users
title = strings.TrimPrefix(title, "/users/")
title = strings.TrimPrefix(title, "~") // Remove leading tilde
// Remove trailing slash if the root of a user dir is being tracked
if strings.Count(title, "/") <= 1 && title[len(title)-1] == '/' {
title = title[:len(title)-1]
}
}
pe.Entries = append(pe.Entries, &PageEntry{
Author: parsed.Host, // Domain is author
Prefix: parsed.Host,
Title: title,
URL: url,
Published: page.Changed,

View File

@ -80,7 +80,7 @@ var data = jsonData{
// PageEntry is a single item on a feed page.
// It is used both for tracked feeds and pages.
type PageEntry struct {
Author string
Prefix string // Feed/log title, author, etc - something before the post title
Title string
URL string
Published time.Time