Skip to content

Support disabling default front matter and add support for Templater #119

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

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

kelszo
Copy link
Contributor

@kelszo kelszo commented Dec 28, 2023

These changes should be completely backwards compatible. The goal of this pull request is to make Media DB more compatible with the Book Search plugin and other plugins. Additionally, to provide a more streamlined and unified way for templating.

Closes: #91

Changes:

  • Use the file path when selecting templates (fallback to filename to be backwards compatible)
  • Add an option to disable the default front matter. Instead the front matter from the template is used.
  • Support Templater, including using the media object. See below.

Example of usage of changes:

movie.md (template)

---
tags: movie
title: {{ title }}
en_title: {{ englishTitle }}
director: 
{{ LIST:director }}
year: {{ year }}
premiere: "{{ premiere }}"
genres:
{{ LIST:genres }}
duration: "{{ duration }}"
actors: 
{{ LIST:actors }}

cover: {{ image }}
created: <% moment(tp.file.creation_date()).format("YYYY-MM-DDTHH:mm") %>
updated: <% moment(tp.file.creation_date()).format("YYYY-MM-DDTHH:mm") %>
watched: false
rating: 

id: {{ id }}
type: {{ type }}
dataSource: {{ dataSource }}
---

# {{title}}
Writers: <% media.writer.map(author => `[[${author}]]`).join(', ') %>

//```json
<% JSON.stringify(media, null, 4) %>
//```

Resulting markdown: Stalker (1979).md

---
tags: movie
title: Stalker
en_title: Stalker
director:
  - Andrei Tarkovsky
year: 1979
premiere: 17/04/1980
genres:
  - Drama
  - Sci-Fi
duration: 162 min
actors:
  - Alisa Freyndlikh
  - Aleksandr Kaydanovskiy
  - Anatoliy Solonitsyn
cover: https://m.media-amazon.com/images/M/MV5BMDgwODNmMGItMDcwYi00OWZjLTgyZjAtMGYwMmI4N2Q0NmJmXkEyXkFqcGdeQXVyNzY1MTU0Njk@._V1_SX300.jpg
created: 2023-12-28T17:36
updated: 2023-12-28T17:36
watched: false
rating: 
id: tt0079944
type: movie
dataSource: OMDbAPI
---


# Stalker
Writers: [[Arkadiy Strugatskiy]], [[Boris Strugatskiy]], [[Andrei Tarkovsky]]

//```json
{
    "type": "movie",
    "title": "Stalker",
    "englishTitle": "Stalker",
    "year": "1979",
    "dataSource": "OMDbAPI",
    "url": "https://www.imdb.com/title/tt0079944/",
    "id": "tt0079944",
    "userData": {
        "watched": false,
        "lastWatched": "",
        "personalRating": 0
    },
    "plot": "A guide leads two men through an area known as the Zone to find a room that grants wishes.",
    "genres": [
        "Drama",
        "Sci-Fi"
    ],
    "director": [
        "Andrei Tarkovsky"
    ],
    "writer": [
        "Arkadiy Strugatskiy",
        "Boris Strugatskiy",
        "Andrei Tarkovsky"
    ],
    "studio": [
        "N/A"
    ],
    "duration": "162 min",
    "onlineRating": 8.1,
    "actors": [
        "Alisa Freyndlikh",
        "Aleksandr Kaydanovskiy",
        "Anatoliy Solonitsyn"
    ],
    "image": "https://m.media-amazon.com/images/M/MV5BYTAzZmEzZjEtNmIzMS00MzlhLWE0Y2ItNDRlNTQwN2E0MDE4XkEyXkFqcGdeQXVyMzY0MTE3NzU@._V1_SX300.jpg",
    "released": true,
    "streamingServices": [],
    "premiere": "17/04/1980"
}
//```

@kelszo kelszo changed the title Support disabling default front matter and add supoort for Templater Support disabling default front matter and add support for Templater Dec 28, 2023
Copy link
Owner

@mProjectsCode mProjectsCode left a comment

Choose a reason for hiding this comment

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

I left some review notes that need to be resolved before I can merge this PR.
The major problem I see is that compromised data in one of the APIs can result in arbitrary JS being run on the user's computer.

@kelszo
Copy link
Contributor Author

kelszo commented Jan 22, 2024

I have resolved all your comments.

I agree with the part about code execution. The simpler solution was to shift the heavy lifting and ensure reliability through the Templater plugin. Now, it adds a <%* block at the top (provided the user has the Templater plugin installed), allowing all subsequent Templater commands to access the media variable.

Please let me know if any comment that I marked as resolved is not satisfactorily addressed, and I will gladly make the necessary corrections.

Copy link
Owner

@mProjectsCode mProjectsCode left a comment

Choose a reason for hiding this comment

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

This looks better :)

There is still one more thing that I would change.

Tie all the templater stuff to it's own setting so that the usage of templater is independent of the "Use default front matter" setting, This setting should mention that it needs templater and make the user aware of the security risk that comes with using it.

@kelszo
Copy link
Contributor Author

kelszo commented Jan 24, 2024

Done! :)

@kelszo kelszo requested a review from mProjectsCode January 24, 2024 21:39
Copy link
Owner

@mProjectsCode mProjectsCode left a comment

Choose a reason for hiding this comment

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

lgtm

@mProjectsCode
Copy link
Owner

can you resolve the conflicts? Then i will merge

@kelszo
Copy link
Contributor Author

kelszo commented Jan 24, 2024

Rebased and ready to merge.

(Fixed a typing error in the latest commit)

@mProjectsCode mProjectsCode merged commit 3cebee4 into mProjectsCode:master Jan 24, 2024
# 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.

Toggle on/off default front matter for Custom Templates
2 participants