-
-
Notifications
You must be signed in to change notification settings - Fork 87
Enhancement: Custom HTML rendering on the card view #513
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
Comments
I started using the https://visitorbadge.io service on my blog to get simple visitor stats per page. That gave me the idea to have a custom renderer that allows me to quickly drop some HTML per card to check these stats on the card/dashboard. The outcome of this looks as follows: This is not yet implemented; just a POC on my end for now to check the possibilities and what the best way would be to get the HTML on the card view. |
|
Option 2Ability to reference a JS file that provides a function like Example: fmExternal = window.fmExternal || {};
fmExternal.getCardHtml = function (filePath, data) {
console.log('getCardHtml', filePath, data)
if (data && data.slug) {
return `<div style="margin-top:0.5rem">html to render</div>`
}
return '';
}
|
Investigating option 2, and must say that this has a lot of potential. Here is an example of how it can be used with, for instance Handlebars import handlebars from 'https://cdn.skypack.dev/handlebars';
const getHtml = (data) => {
const source = `
<div style="margin-top: .5em; font-style: italic;">
{{title}}
</div>
`;
const template = handlebars.compile(source);
return template(data);
}
window.fmExternal = window.fmExternal || {};
fmExternal.getCardHtml = async (filePath, data) => {
return getHtml(data);
} |
Question 1If we would bring this functionality, where would you like to add your HTML? Thinking of the following zones:
Feel free to suggest other zones to which you want to add your HTML. |
Registering your extensibility script(s) "frontMatter.extensibility.scripts": [
"[[workspace]]/external.js"
], |
It is now available in the latest beta, be sure to enable the experimental feature setting: Register your scriptAdd the The scriptAll you need to do for the script is register the window.fmExternal = window.fmExternal || {};
window.fmExternal.getCardFooter = async (filePath, data) => {
return `<span>This is the HTML to render</span>`
} |
I've just published a new extensibility dependency, which makes registration easier. Your script its content looks as follows: import { registerCardFooter } from "https://cdn.skypack.dev/@frontmatter/extensibility";
registerCardFooter(async (filePath, data) => {
return `<span>Your HTML</span>`;
}); |
Testing a bit more with lit webcomponents Screen.Recording.2023-02-26.at.21.27.04.movThe code import {
registerCardFooter
} from "https://cdn.skypack.dev/@frontmatter/extensibility";
import {html, css, LitElement} from 'https://cdn.skypack.dev/lit';
export class SimpleGreeting extends LitElement {
static styles = css`p { color: #44FFD2 }`;
static properties = {
count: {type: Number},
};
constructor() {
super();
this.count = 0;
}
_increment(e) {
this.count++;
}
render() {
return html`
<p><button @click="${this._increment}">Click Me!</button></p>
<p>You've clicked me: ${this.count}!</p>
`;
}
}
customElements.define('simple-counter', SimpleGreeting);
registerCardFooter(async (filePath, data) => {
const slug = encodeURIComponent(data.slug);
return `
<simple-counter></simple-counter>
`;
}); I think this has the potential to allow you to create custom field renderers as well. |
💥 CUSTOM FIELDS 💥 Screen.Recording.2023-02-27.at.12.12.33.mov |
Examples have been added here: https://github.com/FrontMatter/extensibility |
Allow custom HTML to be rendered on the card view. This allows authors to extend their dashboards/cards experience.
The text was updated successfully, but these errors were encountered: