Skip to content

Commit

Permalink
Change popup files to use slugs for dir/filenames
Browse files Browse the repository at this point in the history
After upgrading the GitHub workflow to use upload-artifact@v4, it now
refuses to accept colons within filenames (in order to support NTFS).
Mentions can be URLs (i.e. "https://...") which include colons.
Forcing mentions to be a slug compliant introduces a source of conflict
as many different names can be slugified into the same result. But
we have a conflict detection that panics if that happens, and it's not
happening at the moment at all. So fine.
  • Loading branch information
marcuswhybrow committed Apr 27, 2024
1 parent 05ea40e commit 0bb9504
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion assets/2020-04-26-a-new-landscape-of-life-and-learning.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ DB: Interesting. But now do you think the same opportunities would be had by peo

RP: No, I've heard people express attitudes that you have to be qualified to have access to certain instruments.

[1:35:40] Did you read the book [[Arp, Halton, > Seeing Red]]?
[1:35:40] Did you read the book [[Arp, Halton > Seeing Red]]?

DB: No, I have not.

Expand Down
12 changes: 10 additions & 2 deletions cmd/ray-peat-rodeo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,16 @@ func main() {
return nil
})

catalog.WriteMentionPages()
catalog.WritePopups()
err = catalog.WriteMentionPages()
if err != nil {
log.Fatal("Failed to build mention pages:", err)

}
err = catalog.WritePopups()
if err != nil {
log.Fatal("Failed to build mention popup page:", err)

}

slices.SortFunc(completedAssets, rprCatalog.SortAssetsByDateAdded)

Expand Down
2 changes: 0 additions & 2 deletions internal/catalog/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ type AssetFrontMatter struct {
}

func NewAsset(assetPath string, markdownParser goldmark.Markdown, httpCache *cache.HTTPCache, avatarPaths *AvatarPaths) (*Asset, error) {
fmt.Println("new asset: " + assetPath)
fileName := filepath.Base(assetPath)
fileStem := strings.TrimSuffix(fileName, filepath.Ext(assetPath))

Expand All @@ -123,7 +122,6 @@ func NewAsset(assetPath string, markdownParser goldmark.Markdown, httpCache *cac

// 🔗 Details

fmt.Println("File stem: ", fileStem)
id := fileStem[11:]
urlAbsPath := "/" + id
editPermalink := global.GITHUB_LINK + path.Join("/edit/main", assetPath)
Expand Down
5 changes: 3 additions & 2 deletions internal/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (c *Catalog) WriteMentionPages() error {
primaries := mentionsByFileBySecondary[ast.EmptyMentionablePart]
delete(mentionsByFileBySecondary, ast.EmptyMentionablePart)

file, _ := utils.MakePage(unencode(primary.ID()))
file, _ := utils.MakePage(primary.ID())
component := MentionPage(primary, primaries, mentionsByFileBySecondary, c.HttpCache)
err := component.Render(context.Background(), file)
if err != nil {
Expand All @@ -175,9 +175,10 @@ func (c *Catalog) WritePopups() error {
}
}

f, _ := utils.MakePage(unencode(location))
f, _ := utils.MakePage(location)
component := MentionablePopup(mentionable, mentionsByFile, otherMentionables)
err := component.Render(context.Background(), f)
fmt.Println("Wrote Location: ", location)
if err != nil {
return fmt.Errorf("Failed to render template: %v", err)
}
Expand Down
10 changes: 4 additions & 6 deletions internal/markdown/ast/mentionable_part.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"strings"

"github.com/gosimple/slug"
"github.com/marcuswhybrow/ray-peat-rodeo/internal/cache"
)

Expand All @@ -34,13 +35,10 @@ func (m *MentionablePart) HasPrefix() bool {
func (m *MentionablePart) ID() string {
id := m.Cardinal
if m.HasPrefix() {
id = m.Prefix + "-" + m.Cardinal
id = m.Prefix + " " + m.Cardinal
}
id = strings.ToLower(id)
id = strings.ReplaceAll(id, " ", "-")
id = strings.ReplaceAll(id, "'", "")
id = url.QueryEscape(id)
return id
slug.Lowercase = false
return slug.Make(id)
}

func (m *MentionablePart) TitleOrPrefixFirst() string {
Expand Down

0 comments on commit 0bb9504

Please sign in to comment.