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

Add flag to append hash to pages to ensure unique titles #509

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

pwlandoll
Copy link
Contributor

This adds a command line flag and environment variable to configure mark to append hash values to page titles.

This helps solve the issue where multiple pages with the same name, but under different parents, will conflict (#450).

Another solution could be to allow arbitrary prefix/postfix text, and/or make this computed hash value available as a template variable to be inserted at any point.

README.md Outdated Show resolved Hide resolved
)
path := strings.Join(append(meta.Parents, meta.Space, meta.Title), "/")
pathHash := sha256.Sum256([]byte(path))
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[0:4])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[0:4])
meta.Title = fmt.Sprintf("%s - %x", meta.Title, pathHash[:7])

let's take 7 characters here, just to be safe (in case someone generates a lot of pages)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathHash here is an array of bytes being printed as hexadecimal, so each byte is printed as two characters. The first four bytes and the first eight hexadecimal characters are the same, so I could change it to [:7] of the hex string if you think that is more clear.

Either way, I'll add a comment there since it isn't clear what's happening.

Copy link
Collaborator

@mrueg mrueg Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I didn't see that it's a byte array and hex representation. This looks good (and a comment is a good idea). Ignore my suggestion then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment for clarity, and included other suggestions.

Thanks for the review!

metadata/metadata.go Outdated Show resolved Hide resolved
@pwlandoll pwlandoll requested a review from mrueg October 8, 2024 22:25
@mrueg mrueg merged commit b0f337c into kovetskiy:master Oct 8, 2024
5 checks passed
@mrueg
Copy link
Collaborator

mrueg commented Oct 8, 2024

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants