mirror of
https://github.com/Ellpeck/ObsidianCustomFrames.git
synced 2024-12-22 13:19:24 +01:00
Allow adding a URL suffix to Markdown mode, closes #37
This commit is contained in:
parent
52c1005440
commit
cd0285c2dd
3 changed files with 18 additions and 10 deletions
10
README.md
10
README.md
|
@ -23,18 +23,14 @@ frame: YOUR FRAME'S NAME
|
|||
```
|
||||
~~~
|
||||
|
||||
Optionally, you can also pass custom style settings to the embed, which allows you to change things like the embed's height:
|
||||
~~~
|
||||
```custom-frames
|
||||
frame: YOUR FRAME'S NAME
|
||||
style: SOME CSS
|
||||
~~~
|
||||
Optionally, you can also pass custom style settings to the embed, which allows you to change things like the embed's height, as well as an additional suffix that will be appended to the frame's regular URL, which can be useful for things like displaying a specific note in Google Keep.
|
||||
|
||||
Here's an example that creates a very tall embed using the [Google Keep preset](#-presets):
|
||||
Here's an example using the [Google Keep preset](#-presets):
|
||||
~~~
|
||||
```custom-frames
|
||||
frame: Google Keep
|
||||
style: height: 1000px;
|
||||
urlSuffix: #reminders
|
||||
```
|
||||
~~~
|
||||
|
||||
|
|
12
src/frame.ts
12
src/frame.ts
|
@ -12,7 +12,7 @@ export class CustomFrame {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public create(additionalStyle: string = undefined): any {
|
||||
public create(additionalStyle: string = undefined, urlSuffix: string = undefined): any {
|
||||
let style = `padding: ${this.settings.padding}px;`;
|
||||
if (additionalStyle)
|
||||
style += additionalStyle;
|
||||
|
@ -32,7 +32,15 @@ export class CustomFrame {
|
|||
}
|
||||
this.frame.addClass("custom-frames-frame");
|
||||
this.frame.setAttribute("style", style);
|
||||
this.frame.setAttribute("src", this.data.url);
|
||||
|
||||
let src = this.data.url;
|
||||
if (urlSuffix) {
|
||||
if (!urlSuffix.startsWith("/"))
|
||||
src += "/";
|
||||
src += urlSuffix;
|
||||
}
|
||||
this.frame.setAttribute("src", src);
|
||||
|
||||
return this.frame;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,8 +63,12 @@ export default class CustomFramesPlugin extends Plugin {
|
|||
let style = styleMatch && styleMatch[1].trim();
|
||||
style ||= "height: 600px;";
|
||||
|
||||
let urlSuffixMatch = /urlsuffix:([^\n]+)/gi.exec(s);
|
||||
let urlSuffix = urlSuffixMatch && urlSuffixMatch[1].trim();
|
||||
urlSuffix ||= "";
|
||||
|
||||
let frame = new CustomFrame(this.settings, data);
|
||||
e.appendChild(frame.create(style));
|
||||
e.appendChild(frame.create(style, urlSuffix));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue