react-client icon indicating copy to clipboard operation
react-client copied to clipboard

Add templates support

Open BoFFire opened this issue 4 years ago • 11 comments

Describe the solution you'd like Sometimes users need to create their own MD templates to reuse them such as the YAML metadata or to insert a TOC. Is it possible to allow users to create/insert/modify their own pre-saved templates on new notes/documents by clicking on a button.

Exemple : I want to apply this template to my new note before starting typing text, by choosing a pre-saved template among my own /or/ default templates with a button or a list drawer via the menu or something like that.

---
lang: ar
dir: rtl
title: meta title
description: meta description
tags: features, cool, updated
---

Regards,

BoFFire avatar May 29 '20 19:05 BoFFire

I'm currently thinking about this.

We discussed this at our user meeting@rc3 with some folks and the basic idea was the following:

  • the tag template get's special meaing.
  • if you have any notes in your history with the tag template, the new button gains a dropdown menu:
    • you can either create a new empty note
    • OR
    • you can copy the content of one of your template tagged notes in the new note

The only thing I'm not to sure about is, if we want to give that special meaning to the template tag or if it would be a better idea to introduce a new property to frontmatter and the history entry in the api called template with a simple boolean as value.

The tag solution is easy to implement (it would be a thing for the frontend only, tags already exist), but could be a bit cryptic and hit previous notes, that where not supposed to be included (tags have different meaning).

The custom property solution is a bit more cumbersome to implement, but would only work for the notes, that are supposed to be templates and now false positives. Not sure if a different new frontmatter is more or less cryptic in regards to usability.

DerMolly avatar Jan 07 '21 19:01 DerMolly

A custom property is as easy as a tag to implement.

mrdrogdrog avatar Jan 07 '21 19:01 mrdrogdrog

Some thoughts from my side:

  • I prefer the usage of a dedicated frontmatter field instead of abusing the tags.
  • A template is completely copied into a new pad, isn't it? If so, do these new pads also become templates as they have the template-tag copied with them?
  • A dropdown maybe gets a bit long with many templates. What about a modal which allows to choose a template (or blank) and that allows to enter a custom pad-name (if FreeURL-mode is enabled)?

ErikMichelson avatar Jan 07 '21 21:01 ErikMichelson

A template is completely copied into a new pad, isn't it? If so, do these new pads also become templates as they have the template-tag copied with them?

Obviously you would delete the template attribute after creating the document :yum:

mrdrogdrog avatar Jan 07 '21 21:01 mrdrogdrog

That's the point. If we use a custom frontmatter-property, we could simply replace/remove it when creating a document from a template.

ErikMichelson avatar Jan 07 '21 21:01 ErikMichelson

Another thing to consider: Should the note creation based on a template be done by the backend or by the frontend?

  • If it's done by the frontend, there will be 2 API calls (fetch + create), in total being non-atomic.
  • If it's done by the backend, a new API route extra for this needs to be implemented, which also needs to modify the content in between (remove template: true).

ErikMichelson avatar Jan 08 '21 00:01 ErikMichelson

Why should we need an extra route for creation? We could use the existing "new document" route and add a "template" parameter.

But that's api design. The decision "parameter or new route" is not our department.

Anyway: i would prefer to let the Backend do the heavy work.

mrdrogdrog avatar Jan 08 '21 10:01 mrdrogdrog

This would also make it easier for other clients like the cli.

mrdrogdrog avatar Jan 08 '21 10:01 mrdrogdrog

I don't know if this should be a seperate issue, so here it goes:

https://hedge.doc/new?content=...

When creating a new pad, allow content to be passed in via a query parameter. This would be limited to ~1500 chars because of url limits and encoding bloat, but I assume this would not be that hard to implement ( ala if (queryParams.content && note.content.length == 0) note.content = queryParams.content)

jfowl avatar May 04 '21 12:05 jfowl

@jfowl this would be a separate issue. But I also don't see the use case.

mrdrogdrog avatar May 04 '21 12:05 mrdrogdrog

Remember that you'll be able to POST content to an API-endpoint for creating a note with a given content. Therefore, I support @mrdrogdrog in this.

ErikMichelson avatar May 04 '21 12:05 ErikMichelson