Skip to content

Commit

Permalink
fix: use alt text for linked files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Jul 7, 2022
1 parent 68a00b8 commit 1b800cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mkdocsPublisher/utils/convertText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function convertLinkCitation(fileContent: string, settings: MkdocsPublicationSet
return fileContent;
}
for (const linkedFile of linkedFiles) {
const pathInGithub = createRelativePath(sourceFile, linkedFile.linked, metadataCache, settings).replace('.md', '');
const pathInGithub = createRelativePath(sourceFile, linkedFile, metadataCache, settings).replace('.md', '');
const regexToReplace = new RegExp(`(\\[{2}${linkedFile.linkFrom}(\\|.*)?\\]{2})|(\\[.*\\]\\(${linkedFile.linkFrom}\\))`, 'g');
const matchedLink = fileContent.match(regexToReplace);
if (matchedLink) {
Expand Down
15 changes: 8 additions & 7 deletions mkdocsPublisher/utils/filePathConvertor.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {MetadataCache, TFile} from "obsidian";
import {MetadataCache, Notice, TFile} from "obsidian";
import {folderSettings, MkdocsPublicationSettings} from "../settings/interface";

function createRelativePath(sourceFile: TFile, targetFile: TFile, metadata: MetadataCache, settings: MkdocsPublicationSettings) {
function createRelativePath(sourceFile: TFile, targetFile: {linked: TFile, linkFrom: string, altText: string }, metadata: MetadataCache, settings: MkdocsPublicationSettings) {
/**
* Create relative path from a sourceFile to a targetPath. If the target file is a note, only share if the frontmatter sharekey is present and true
* @param sourceFile: TFile, the shared file containing all links, embed etc
* @param targetFile: Tfile, the targeted file
* @param targetFile: {linked: TFile, linkFrom: string, altText: string}
* @param settings: MkdocsPublicationSettings
* @param metadata: metadataCache
* @return string : relative created path
*/
const sourcePath = getReceiptFolder(sourceFile, settings, metadata);
const frontmatter = metadata.getCache(targetFile.path) ? metadata.getCache(targetFile.path).frontmatter : null;
if (targetFile.extension === '.md' && (!frontmatter || !frontmatter[settings.shareKey])) {
return sourceFile.name;
const frontmatter = metadata.getCache(targetFile.linked.path) ? metadata.getCache(targetFile.linked.path).frontmatter : null;
new Notice(targetFile.altText) //because I need to know what is displayed here... I need more docs for the API ;;
if (targetFile.linked.extension === '.md' && (!frontmatter || !frontmatter[settings.shareKey])) {
return targetFile.altText;
}
const targetPath = targetFile.extension === 'md' ? getReceiptFolder(targetFile, settings, metadata) : getImageLinkOptions(targetFile, settings);
const targetPath = targetFile.linked.extension === 'md' ? getReceiptFolder(targetFile.linked, settings, metadata) : getImageLinkOptions(targetFile.linked, settings);
const sourceList = sourcePath.split('/');
const targetList = targetPath.split('/');
const diffSourcePath = sourceList.filter(x => !targetList.includes(x));
Expand Down

0 comments on commit 1b800cd

Please sign in to comment.