-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 ~shareTemplate and #shareExternalLink #4298
Conversation
const subRoot = getSharedSubTreeRoot(note); | ||
const opts = {note, header, content, isEmpty, subRoot, assetPath, appPath}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all currently passed to the user's custom template as well, should we only pass a subset to the user? Or are there other things that would be useful to the user template that are not currently passed?
Either way this creates a sort of pseudo-api so it would be good to be certain of what should be passed and try not to change it much going forward. But I would still call user templates an "at your own risk" type of extension.
I started looking at this, but it will likely take some time ... |
Take all the time you need, I'm not in a rush |
Do you want me to split off the search API stuff into its own PR to be evaluated separately from custom templates/external links? |
No, not needed. Seems OK to me ... |
Alright I'll update this PR with requested changes then |
@rauenzi pls let me know once you're done with the changes... |
@zadam that last commit should address everything we talked about |
@zadam Sorry didn't realize there was also a merge conflict, I've resolved it so this should be ready to review again |
@rauenzi Still would love to know how ~shareTemplate works, looks great from what is said in first post. |
Hi @deajan not sure what is unclear from the first post but I will try to restate. |
@rauenzi You are amazing! I used the |
Glad to hear it worked out @dvai! |
Hey @rauenzi , Thanks for adding this capability. It's exactly what I would like to do. I'm an error when trying to use it. When i click the share link it gives this error: here is the attribute on the parent note. Is there anything I'm missing? Thanks for the help! Mike |
Would need to see the ejs template if you mean an error on the share page itself. If you mean when clicking the link in the app's GUI that's likely a separate issue. |
The template should have the EJS type not plaintext. You might have to go into settings and enable that language. I'm on my phone so I cannot provide screenshot guidance. |
Setting the template language to EJS worked for me. Additionally I had to move the template file in the shared folder. Thanks for the help. |
This PR does 3 things, I can remove them or split them as up as needed.
1.
~shareTemplate
This implements custom use share templates as I mentioned here #3429 (comment). A user can set
~shareTemplate(inheritable)=xxx
to use their own template for the entire tree, and any subnote to the~shareTemplate
will be a validinclude()
for EJS. It also automatically falls back to use the default view in the case that rendering with the user template fails so something is still shown.2.
shareExternalLink
This is a simple label attribute that allows a note in the share tree to act as an external link to an external website. Useful for referencing other sites or documentation withing your own share tree or even using the external link note as a single-source of truth and link to it internally from other notes.
3.
/share/api/search
This is the one I'm least confident in and I'm sure changes will be required, but it adds a search api for the share tree for future use for things like #3430. I tried to follow the standard in
routes.js
but couldn't find any other way but requiring:noteId
in the api to ensure we were checking the right tree.I did not modify the current default template or js or css in this PR to support this search functionality (or improve the default as requested in #3429) because I wanted to get this part approved first. I do know that this api works as I'm currently using it (and the other two above) for https://trilium.rocks/
Question
I asked it briefly in #3429 but it kinda got buried, but are the default templates open for changes? I've been working on improving the default share theme (as shown in that issue) but I'd also like to improve the html/templates to make theming and customizing a little easier, as well as adding in the search functionality from above. But I know that changing those could be considered breaking backwards compatibility for those that have written custom js/css for their shared trees.