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 ~shareTemplate and #shareExternalLink #4298

Merged
merged 5 commits into from
Oct 9, 2023
Merged

Conversation

zerebos
Copy link
Collaborator

@zerebos zerebos commented Sep 30, 2023

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 valid include() 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.

src/share/routes.js Outdated Show resolved Hide resolved
src/views/share/page.ejs Outdated Show resolved Hide resolved
src/views/share/tree_item.ejs Outdated Show resolved Hide resolved
src/share/routes.js Outdated Show resolved Hide resolved
const subRoot = getSharedSubTreeRoot(note);
const opts = {note, header, content, isEmpty, subRoot, assetPath, appPath};
Copy link
Collaborator Author

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.

@deajan
Copy link
Contributor

deajan commented Oct 1, 2023

@rauenzi Care to explain what shareTemplate does ?
Would it resolve my share parameter inheritance issue #4282 ?

@zerebos
Copy link
Collaborator Author

zerebos commented Oct 1, 2023

@deajan It's explained briefly the in the first post, but it is unrelated to your issue #4282 and would not fix it

@zadam
Copy link
Owner

zadam commented Oct 3, 2023

I started looking at this, but it will likely take some time ...

@zerebos
Copy link
Collaborator Author

zerebos commented Oct 4, 2023

Take all the time you need, I'm not in a rush

src/share/routes.js Outdated Show resolved Hide resolved
src/share/routes.js Outdated Show resolved Hide resolved
@zerebos
Copy link
Collaborator Author

zerebos commented Oct 7, 2023

Do you want me to split off the search API stuff into its own PR to be evaluated separately from custom templates/external links?

@zadam
Copy link
Owner

zadam commented Oct 7, 2023

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 ...

@zerebos
Copy link
Collaborator Author

zerebos commented Oct 7, 2023

Alright I'll update this PR with requested changes then

@zadam
Copy link
Owner

zadam commented Oct 8, 2023

@rauenzi pls let me know once you're done with the changes...

@zerebos
Copy link
Collaborator Author

zerebos commented Oct 8, 2023

@zadam that last commit should address everything we talked about

@zerebos
Copy link
Collaborator Author

zerebos commented Oct 8, 2023

@zadam Sorry didn't realize there was also a merge conflict, I've resolved it so this should be ready to review again

@zadam zadam merged commit db8014c into zadam:master Oct 9, 2023
1 of 2 checks passed
@deajan
Copy link
Contributor

deajan commented Oct 11, 2023

@rauenzi Still would love to know how ~shareTemplate works, looks great from what is said in first post.

@zerebos
Copy link
Collaborator Author

zerebos commented Oct 11, 2023

Hi @deajan not sure what is unclear from the first post but I will try to restate. ~shareTemplate allows you to use an Embedded JavaScript (EJS) note within your share tree as the template/html for your shared note(s). Any EJS child notes of the target templates will be passed to the EJS include function. As an example the default one used by Trilium can be seen here: https://github.com/zadam/trilium/blob/master/src/views/share/page.ejs

@dvai
Copy link

dvai commented Dec 11, 2023

@rauenzi You are amazing! I used the ~shareTemplate feature to create a personal blog template (your website https://trilium.rocks/ gave me great inspiration, thank you). Here is my personal blog address: https://ankia.top/. Feel free to visit.

@zerebos
Copy link
Collaborator Author

zerebos commented Dec 11, 2023

Glad to hear it worked out @dvai!

@mbseid
Copy link

mbseid commented Feb 22, 2024

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: {"message":"Cannot read properties of undefined (reading 'type')"}.

here is the attribute on the parent note.
image

image

Is there anything I'm missing? Thanks for the help!

Mike

@zerebos
Copy link
Collaborator Author

zerebos commented Feb 22, 2024

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.

@mbseid
Copy link

mbseid commented Feb 22, 2024

Thanks for the fast response. Here is the ejs template.
image

Is there anything I need to do to the note to set the type? Additional context, I installed Trilium yesterday and I'm very so there may be concepts I'm missing.

Thanks again

@zerebos
Copy link
Collaborator Author

zerebos commented Feb 22, 2024

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.

@mbseid
Copy link

mbseid commented Feb 22, 2024

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.

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.

5 participants