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

Custom page preview: Automatic generation using plugins #1

Open
dxcore35 opened this issue Mar 5, 2023 · 12 comments
Open

Custom page preview: Automatic generation using plugins #1

dxcore35 opened this issue Mar 5, 2023 · 12 comments

Comments

@dxcore35
Copy link

dxcore35 commented Mar 5, 2023

Hello.

I tried to replicate and build the text formatting from your snippet. To build the snippet automatically from note's metadata. But as you see the CSS is not behaving in same way if it is inserted as text.

  1. It is visible in note body
  2. It is not rendered inside preview popup

Markdown

Screenshot 2023-03-05 at 18 15 07

Preview mode

Screenshot 2023-03-05 at 18 14 27

Do you have any ideas how to fix it? Possible with adding some CSS class?

@zamsyt
Copy link
Owner

zamsyt commented Mar 5, 2023

The issue seems to be that your Dataviewjs block creates the callout at a different position in the DOM than normal, and my CSS doesn't account for that. Could be solved by changing the CSS, but here's a different way to do it with Dataview without changing the CSS:

> [!page preview]
> `=this.summary`
> 
> ```dataviewjs
> dv.el("div", "![[" + dv.current().cover + "]]")
> ```

I think there might be a simpler way to do the image embed, but not sure, I'm not that familiar with Dataview. This also seems to render unreliably in Live Preview for me.

@zamsyt
Copy link
Owner

zamsyt commented Mar 5, 2023

Depending on your needs, another option would be to mark the values as Dataview inline fields (instead of storing them in the yaml):

> [!page preview]
> (summary:: Summary text)
> 
> (cover:: ![[image 123.png]])

And a snippet to reset their appearance:

.dataview.inline-field-standalone-value {
    padding: 0;
    font-family: inherit;
    background-color: transparent;
    color: inherit;
}

@dxcore35
Copy link
Author

dxcore35 commented Mar 7, 2023

I check both solution but non are really good solutions :D What about trying the way by adaption of CSS?

@zamsyt
Copy link
Owner

zamsyt commented Mar 7, 2023

Here's a patched version for you (Warning: Probably broken): Custom page preview (ignore position).css. I removed everything that checks the exact position of the page preview in the DOM hierarchy. I also added an extra use of the :has selector, and it means the preview is probably broken with installer versions older than v1.1.9. I also suspect this will create unexpected behavior with embeds, but haven't tested the extent of it.

I think the better solution would be to find out how to generate the correct html output using DataviewJS or Templater if possible.

edit: To avoid the margins added by the paragraph element you're creating, use a div instead:

dv.el("div", "> [!page preview]\n> " + summary + "\n>\n ![[" + cover + "]]")

@zamsyt
Copy link
Owner

zamsyt commented Mar 7, 2023

If you want to stick to this solution (and assuming you run into issues with the patch), I could probably add additional checks to the snippet for the DataviewJS output for a more robust solution

@dxcore35
Copy link
Author

dxcore35 commented Mar 8, 2023

I have used your snippet above. My installer is 1.1.9. But the preview is different and as you see it is still visible in page.

CODE


cover: "Pasted image 20230126162029.png"
summary: Testing view

let cover = dv.current().cover
let summary = dv.current().summary

dv.el("div", "> [!page preview]\n> " + summary + "\n>\n ![[" + cover + "]]")


Page preview

Screenshot 2023-03-08 at 11 42 19

Emblemed preview

Screenshot 2023-03-08 at 11 42 09

@zamsyt
Copy link
Owner

zamsyt commented Mar 8, 2023

The screenshots look as if you don't have the snippet enabled (or you have the unpatched snippet).

This is how it looks like for me in the sandbox vault with just the patched snippet and Dataview installed (with JS queries enabled)

Note content:

---
cover: "Pasted image 20230308145507.png"
summary: Testing view
---

```dataviewjs
let cover = dv.current().cover
let summary = dv.current().summary
dv.el("div", "> [!page preview]\n> " + summary + "\n>\n ![[" + cover + "]]")
```

Live preview:
image

image

@zamsyt
Copy link
Owner

zamsyt commented Mar 8, 2023

I'd also be interested to hear what your issues were with the other solutions

@dxcore35
Copy link
Author

dxcore35 commented Mar 9, 2023

Now your code works! The custom CSS was disabled as I renamed it...
I tried to create custom dv.view and add whole script there.

Here is the script:
dx_Project_preview.zip

Here is how you need to call it from note text:


cover: "Pasted image 20230126162029.png"
summary: Testing view

await dv.view("dx_Project_preview")

But the result looks like this:

Screenshot 2023-03-09 at 13 03 07

@dxcore35
Copy link
Author

dxcore35 commented Mar 9, 2023

Also there is a side affect, that the notes without this code are previewed empty

@zamsyt
Copy link
Owner

zamsyt commented Mar 9, 2023

Also there is a side affect, that the notes without this code are previewed empty

I fixed that in patch 2

@dxcore35
Copy link
Author

I have indeed fixed the side effect but now the the DataviewJS and neither dv.view methods are not producing preview.

@zamsyt zamsyt changed the title Custom page preview (builded via dataviewJS) Custom page preview: Automatic generation using plugins Apr 6, 2023
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

No branches or pull requests

2 participants