|
1 | 1 | import { MarkdownView, Notice, parseYaml, Plugin, stringifyYaml, TFile, TFolder } from 'obsidian'; |
2 | | -import { requestUrl, normalizePath } from 'obsidian'; // Add requestUrl import |
| 2 | +import { requestUrl, normalizePath } from 'obsidian'; |
3 | 3 | import type { MediaType } from 'src/utils/MediaType'; |
4 | 4 | import { APIManager } from './api/APIManager'; |
5 | 5 | import { BoardGameGeekAPI } from './api/apis/BoardGameGeekAPI'; |
@@ -59,7 +59,6 @@ export default class MediaDbPlugin extends Plugin { |
59 | 59 | this.apiManager.registerAPI(new ComicVineAPI(this)); |
60 | 60 | this.apiManager.registerAPI(new MobyGamesAPI(this)); |
61 | 61 | this.apiManager.registerAPI(new GiantBombAPI(this)); |
62 | | - // this.apiManager.registerAPI(new LocGovAPI(this)); // TODO: parse data |
63 | 62 |
|
64 | 63 | this.mediaTypeManager = new MediaTypeManager(); |
65 | 64 | this.modelPropertyMapper = new PropertyMapper(this); |
@@ -157,12 +156,6 @@ export default class MediaDbPlugin extends Plugin { |
157 | 156 | }); |
158 | 157 | } |
159 | 158 |
|
160 | | - /** |
161 | | - * first very simple approach |
162 | | - * TODO: |
163 | | - * - replace the detail query |
164 | | - * - maybe custom link syntax |
165 | | - */ |
166 | 159 | async createLinkWithSearchModal(): Promise<void> { |
167 | 160 | const apiSearchResults = await this.modalHelper.openAdvancedSearchModal({}, async advancedSearchModalData => { |
168 | 161 | return await this.apiManager.query(advancedSearchModalData.query, advancedSearchModalData.apis); |
@@ -381,18 +374,7 @@ export default class MediaDbPlugin extends Plugin { |
381 | 374 | * @param options |
382 | 375 | */ |
383 | 376 | async generateMediaDbNoteContents(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions): Promise<string> { |
384 | | - const template = await this.mediaTypeManager.getTemplate(mediaTypeModel, this.app); |
385 | | - |
386 | | - return this.generateContentWithDefaultFrontMatter(mediaTypeModel, options, template); |
387 | | - |
388 | | - // if (this.settings.useDefaultFrontMatter || !template) { |
389 | | - // return this.generateContentWithDefaultFrontMatter(mediaTypeModel, options, template); |
390 | | - // } else { |
391 | | - // return this.generateContentWithCustomFrontMatter(mediaTypeModel, options, template); |
392 | | - // } |
393 | | - } |
394 | | - |
395 | | - async generateContentWithDefaultFrontMatter(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions, template?: string): Promise<string> { |
| 377 | + let template = await this.mediaTypeManager.getTemplate(mediaTypeModel, this.app); |
396 | 378 | let fileMetadata: Record<string, unknown>; |
397 | 379 |
|
398 | 380 | if (this.settings.useDefaultFrontMatter) { |
@@ -421,48 +403,6 @@ export default class MediaDbPlugin extends Plugin { |
421 | 403 | return fileContent; |
422 | 404 | } |
423 | 405 |
|
424 | | - async generateContentWithCustomFrontMatter(mediaTypeModel: MediaTypeModel, options: CreateNoteOptions, template: string): Promise<string> { |
425 | | - const regExp = new RegExp(this.frontMatterRexExpPattern); |
426 | | - |
427 | | - const frontMatter = this.getMetaDataFromFileContent(template); |
428 | | - let fileContent: string = template.replace(regExp, ''); |
429 | | - |
430 | | - // Updating a previous file |
431 | | - if (options.attachFile) { |
432 | | - const previousMetadata = this.app.metadataCache.getFileCache(options.attachFile)?.frontmatter ?? {}; |
433 | | - |
434 | | - // Use contents (below front matter) from previous file |
435 | | - fileContent = await this.app.vault.read(options.attachFile); |
436 | | - |
437 | | - fileContent = fileContent.replace(regExp, ''); |
438 | | - fileContent = fileContent.startsWith('\n') ? fileContent.substring(1) : fileContent; |
439 | | - |
440 | | - // Update updated front matter with entries from the old front matter, if it isn't defined in the new front matter |
441 | | - Object.keys(previousMetadata).forEach(key => { |
442 | | - const value: unknown = previousMetadata[key]; |
443 | | - |
444 | | - if (!frontMatter[key] && value) { |
445 | | - frontMatter[key] = value; |
446 | | - } |
447 | | - }); |
448 | | - } |
449 | | - |
450 | | - // Ensure that id, type, and dataSource are defined |
451 | | - frontMatter.id ??= mediaTypeModel.id; |
452 | | - frontMatter.type ??= mediaTypeModel.type; |
453 | | - frontMatter.dataSource ??= mediaTypeModel.dataSource; |
454 | | - |
455 | | - if (this.settings.enableTemplaterIntegration && hasTemplaterPlugin(this.app)) { |
456 | | - // Only support stringifyYaml for templater plugin |
457 | | - // Include the media variable in all templater commands by using a top level JavaScript execution command. |
458 | | - fileContent = `---\n<%* const media = ${JSON.stringify(mediaTypeModel)} %>\n${stringifyYaml(frontMatter)}---\n${fileContent}`; |
459 | | - } else { |
460 | | - fileContent = `---\n${stringifyYaml(frontMatter)}---\n${fileContent}`; |
461 | | - } |
462 | | - |
463 | | - return fileContent; |
464 | | - } |
465 | | - |
466 | 406 | async attachFile(fileMetadata: Metadata, fileContent: string, fileToAttach?: TFile): Promise<{ fileMetadata: Metadata; fileContent: string }> { |
467 | 407 | if (!fileToAttach) { |
468 | 408 | return { fileMetadata: fileMetadata, fileContent: fileContent }; |
|
0 commit comments