Skip to content
New issue

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

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

Already on GitHub? # to your account

FOAM_SLUG template variable addition #865

Merged
merged 17 commits into from
Feb 20, 2022
Merged

FOAM_SLUG template variable addition #865

merged 17 commits into from
Feb 20, 2022

Conversation

techCarpenter
Copy link
Contributor

This is my first open source contribution. I'm excited to contribute and also eager to do things right so any feedback on this PR is appreciated!


This contribution addresses the discussion about slugifying wikilinks

The FOAM_TITLE_SLUG variable will be available in foam templates. When the note title is entered with Create New Note, a slug is created by github-slugger that can then be used as part of the file name.

Example:

Variable Value
FOAM_TITLE My new note
FOAM_TITLE_SLUG my-new-note

@techCarpenter techCarpenter marked this pull request as ready for review December 12, 2021 04:16
@chrisUsick
Copy link
Contributor

I wanted to clarify something. Is it improper to use FOAM_TITLE in the file path? That, plus other recent fixes to slugs finally allowed for wikilinks to work well. I appreciate having the wikilink text having the capitalization and spaces. I have a lot of notes that use this format and would like to know if that’s becoming an unsupported pattern.
Another thing I’m unclear on is whether FOAM_TITLE style wikiklinks affect publishing? It sounds like it might not work.

Copy link
Collaborator

@riccardoferretti riccardoferretti left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @techCarpenter! I have left a few comments for you, let me know your thoughts

@techCarpenter
Copy link
Contributor Author

@riccardoferretti Thank you for the notes, I'll address them!

@techCarpenter
Copy link
Contributor Author

I wanted to clarify something. Is it improper to use FOAM_TITLE in the file path? That, plus other recent fixes to slugs finally allowed for wikilinks to work well. I appreciate having the wikilink text having the capitalization and spaces. I have a lot of notes that use this format and would like to know if that’s becoming an unsupported pattern. Another thing I’m unclear on is whether FOAM_TITLE style wikiklinks affect publishing? It sounds like it might not work.

@chrisUsick I was told by @riccardoferretti that using FOAM_TITLE is the default way to do wikilinks in Foam. I suspect there could be issues when publishing files that have spaces in the filename.

@chrisUsick
Copy link
Contributor

chrisUsick commented Dec 12, 2021

@chrisUsick I was told by @riccardoferretti that using FOAM_TITLE is the default way to do wikilinks in Foam. I suspect there could be issues when publishing files that have spaces in the filename.

Ah, I see that in the comments. Thanks!

@memeplex
Copy link
Contributor

memeplex commented Dec 13, 2021

The github slugger is not actually used, it seems to be a legacy part of Foam, I've opened a PR to remove the remnants (#872). Having a title is not required, but if your note has a title it's best to name the file after that title, or some transformation of it (but no transformation is enforced or preferred, therefore you have to do it manually, so again: better name your note after the title). Except that @riccardoferretti considers that some default transformation is desirable for templates. The problem I see with that is that one user may prefer this-is-my-note.md, while another likes this_is_my_note.md better, yet another one choses ThisIsMyNote.md, a fourth one goes with This is my note.md and a dendron-minded guy is used to this.is.my.note.md. So short of having some kind of slug expression language there is no way to make everyone happy. IMHO the most sensible approach is that slug = filename = title (the title may be later made more verbose or whatever by the user, I'm just talking about defaults) and that Foam should support that convention OOTB but also allow the user to choose another convention, even if it's a bit more cumbersome to work with. This is what Obsidian does also.

@riccardoferretti
Copy link
Collaborator

The only constraints that Foam gives you is that wikilinks use the file name to find the resource.
As long as you are fine with this premise, you can use anything you want to name your files, whether the title, the slug, ... or something totally different (e.g. timestamp).

Except that @riccardoferretti considers that some default transformation is desirable for templates

This is not about templates, per my comment above, you can pick whatever path you desire.

What would need a transformation might be the [[wikilink key]], almost as an automatic alias (or, more precisely, a key normalization function). The way Foam works would actually support it fairly easily, but atm I am not inclined to have much magic happen there, as there are still a few wrinkles to iron before considering this option.

To summarize, sure you can have a FOAM_TITLE = File with Slug and via FOAM_TITLE_SLUG create your /path/to/file-with-slug.md, be aware that you will need to refer to such file as [[file-with-slug]] and not [[File With Slug]].

@memeplex
Copy link
Contributor

memeplex commented Dec 14, 2021

This is not about templates, per my comment above, you can pick whatever path you desire.

What I meant is that when you create a template you have a title but not a slug, except when slug = title. But, sure, the same happens when you enter [[slug]] and ctrl-click on the placeholder link, if you want title = slug you will be fine with the default, otherwise you will have to edit the title. So, I was saying that except that you prefer some slug convention over the others, or are willing to provide a way to configure a programmable slugger, all conventions but title = slug will require extra manual intervention. Which is fine for me.

@riccardoferretti
Copy link
Collaborator

relevant comment: #872 (comment)

@memeplex
Copy link
Contributor

Despite the outcome of the discussion ongoing in #872 I'd suggest to rename FOAM_TITLE_SLUG to FOAM_SLUG. slug is or may be used in other contexts, not necessarily derived from the title. Besides FOAM_SLUG is shorter.

@riccardoferretti
Copy link
Collaborator

What do you mean by "slug is or may be used in other contexts"?

@memeplex
Copy link
Contributor

What do you mean by "slug is or may be used in other contexts"?

More or less your open questions in #872 (comment). I mean, in this context it's clear that slug is something created from a title, but in other yet to be defined contexts that may not be the case. For example, in the ctrl-click over [[a-placeholder]] case maybe we end up creating a # A placeholder title from the slug. I believe a more neutral terminology of slug, like the slug being a feature of the note, instead of title slug, could be preferable.

- Remove unused resolveFoamTitleSlug() function
- Await resolveFoamTitle() in resolver promises
- Rename `FOAM_TITLE_SLUG` to `FOAM_SLUG`
- initialize `foamTitle` to `null`
@techCarpenter techCarpenter changed the title FOAM_TITLE_SLUG template variable addition FOAM_SLUG template variable addition Feb 17, 2022
Copy link
Contributor Author

@techCarpenter techCarpenter left a comment

Choose a reason for hiding this comment

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

All changes are up to date with comments by @riccardoferretti. New foam template variable FOAM_SLUG is available to use.

Copy link
Collaborator

@riccardoferretti riccardoferretti left a comment

Choose a reason for hiding this comment

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

Looking good, thanks @techCarpenter!

@riccardoferretti riccardoferretti merged commit 0d90fc5 into foambubble:master Feb 20, 2022
@techCarpenter
Copy link
Contributor Author

PR merged into master branch

@techCarpenter techCarpenter deleted the foam-title-slug branch February 21, 2022 14:14
@riccardoferretti
Copy link
Collaborator

@allcontributors add @techCarpenter for code

@allcontributors
Copy link
Contributor

@riccardoferretti

I've put up a pull request to add @techCarpenter! 🎉

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

Successfully merging this pull request may close these issues.

4 participants