Skip to content

Commit 9942092

Browse files
committed
feat: use adaptive width and height
!! VERY DANGEROUS !! Use adaptive width and height from the base config.
1 parent 415e8bc commit 9942092

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/main.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command, Plugin, TFile } from 'obsidian';
1+
import { Command, parseYaml, Plugin, TFile } from 'obsidian';
22
import { Base, PluginSettings } from './types';
33
import { generate } from "./generator";
44
import { SettingTab } from './settings';
@@ -11,7 +11,8 @@ const defaultSettings: PluginSettings = {
1111

1212
export default class ThumbnailPlugin extends Plugin {
1313
settings: PluginSettings;
14-
bases: Base[];
14+
bases: Base[] = [];
15+
files: TFile[] = [];
1516

1617
async onload() {
1718
await this.loadSettings();
@@ -23,12 +24,17 @@ export default class ThumbnailPlugin extends Plugin {
2324
let bases = await getBases(this);
2425
console.debug(bases);
2526
for (const base of bases) {
26-
console.debug(base);
27+
// TODO: automatic rebuilding of thumbnails upon changes in base cards config
28+
// TODO: automatic rebulding of thumbnails upon changes in file
29+
// TODO: make this safer
30+
const width = parseYaml(base.content).views[0].cardSize as number;
31+
const height = width * parseYaml(base.content).views[0].imageAspectRatio;
2732
let files = getFiles(this.app, base);
2833
for (const file of files) {
2934
console.debug(file);
3035
if (file instanceof TFile) {
31-
let path = await generate(this.app, this, file, 16, 9);
36+
console.debug(height, width)
37+
let path = await generate(this.app, this, file, height, width);
3238
if (typeof path === "string") {
3339
await this.app.fileManager.processFrontMatter(file, (frontmatter: Record<string, unknown>) => {
3440
frontmatter["thumbnail"] = `[[${path}]]`;
@@ -66,7 +72,7 @@ export default class ThumbnailPlugin extends Plugin {
6672
console.debug("Automatically looking for bases...");
6773
await getBases(this);
6874
})().catch(e => console.error("Thumbnails -", e));
69-
}, 1 * 60 * 1000));
75+
}, 10 * 1000));
7076
}
7177

7278
onunload() {

0 commit comments

Comments
 (0)