Skip to content

Commit

Permalink
fix: error using category frontmatter because of metadataCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jun 12, 2022
1 parent 02b2b31 commit 79c2dbe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mkdocsPublisher/githubInteraction/getFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class GetFiles {
file.path
).frontmatter;
if (frontMatter && frontMatter[shareKey] === true) {
const filepath = getReceiptFolder(file, this.settings)
const filepath = getReceiptFolder(file, this.settings, this.metadataCache);
allFileWithPath.push(filepath);
}
}
Expand Down
6 changes: 3 additions & 3 deletions mkdocsPublisher/githubInteraction/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class MkdocsPublish {
async publish(file: TFile, one_file = false, ref = "main") {
const shareFiles = new GetFiles(this.vault, this.metadataCache, this.settings, this.octokit);
const sharedKey = this.settings.shareKey;
const frontmatter = this.metadataCache.getCache(file.path).frontmatter;
const frontmatter = this.metadataCache.getFileCache(file).frontmatter;
if (
!frontmatter ||
!frontmatter[sharedKey] ||
Expand All @@ -50,9 +50,9 @@ export default class MkdocsPublish {
let text = await this.vault.cachedRead(file);
const linkedImage = shareFiles.getLinkedImage(file);
const linkedFiles = shareFiles.getLinkedFiles(file);
text = convertLinkCitation(text, this.settings, linkedFiles)
text = convertLinkCitation(text, this.settings, linkedFiles, this.metadataCache)
text = convertWikilinks(text, this.settings, linkedFiles);
const path = getReceiptFolder(file, this.settings)
const path = getReceiptFolder(file, this.settings, this.metadataCache)
await this.uploadText(file.path, text, path, file.name, ref);
if (linkedImage.length > 0 && this.settings.transferEmbedded) {
for (const image of linkedImage) {
Expand Down
10 changes: 5 additions & 5 deletions mkdocsPublisher/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {App, Notice, TFile} from 'obsidian'
import {App, Notice, TFile, MetadataCache} from 'obsidian'
import {MkdocsPublicationSettings} from '../settings/interface'
import MkdocsPublish from "../githubInteraction/upload";

Expand Down Expand Up @@ -61,12 +61,12 @@ function convertWikilinks(fileContent: string, settings: MkdocsPublicationSettin
return fileContent;
}

function getReceiptFolder(file: TFile, settings:MkdocsPublicationSettings) {
function getReceiptFolder(file: TFile, settings:MkdocsPublicationSettings, metadataCache: MetadataCache) {
const folderDefault = settings.folderDefaultName;
let path = settings.folderDefaultName.length > 0 ? settings.folderDefaultName + "/" + file.name : file.name;

if (settings.downloadedFolder === "yamlFrontmatter") {
const frontmatter = this.metadataCache.getCache(file.path).frontmatter
const frontmatter = metadataCache.getCache(file.path).frontmatter
let folderRoot = settings.rootFolder;
if (folderRoot.length > 0) {
folderRoot = folderRoot + "/";
Expand All @@ -85,12 +85,12 @@ function getReceiptFolder(file: TFile, settings:MkdocsPublicationSettings) {
return path
}

function convertLinkCitation(fileContent: string, settings: MkdocsPublicationSettings, linkedFiles : {linked: TFile, linkFrom: string, altText: string}[]) {
function convertLinkCitation(fileContent: string, settings: MkdocsPublicationSettings, linkedFiles : {linked: TFile, linkFrom: string, altText: string}[], metadataCache: MetadataCache) {
if (!settings.convertForGithub) {
return fileContent;
}
for (const linkedFile of linkedFiles) {
const pathInGithub = getReceiptFolder(linkedFile.linked, settings)
const pathInGithub = getReceiptFolder(linkedFile.linked, settings, metadataCache )
fileContent = fileContent.replace(linkedFile.linkFrom, pathInGithub)
}
return fileContent;
Expand Down

0 comments on commit 79c2dbe

Please sign in to comment.