Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
Glob stat
Refresh after export
  • Loading branch information
symunona committed Nov 5, 2023
1 parent 3bba334 commit 9771e00
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 30 deletions.
3 changes: 1 addition & 2 deletions src/export/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export class Exporter {
data.value.values,
settings
);
// console.warn(exportFileMap)
log(
`Found ${data.value.values.length} files for`,
` filter: '${settings.exportQuery}'`,
Expand Down Expand Up @@ -167,7 +166,7 @@ export class Exporter {

// Save the last export map so we can see what's already exported.
settings.lastExport = lastExport
console.warn(settings.name, lastExport)
// console.warn(settings.name, lastExport)

this.plugin.saveSettings();
this.display.applyStatusIcons(settings.lastExport, settings);
Expand Down
4 changes: 1 addition & 3 deletions src/export/get-markdown-attachments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function saveAttachmentToLocation(
attachment: AttachmentLink,
exportProperties: ExportProperties
) {
const imageLink = decodeURI(attachment.originalPath);
const imageLink = decodeURIComponent(attachment.originalPath);

const imageName = basename(imageLink);

Expand All @@ -108,8 +108,6 @@ async function saveAttachmentToLocation(
// For now, let's settle with "asset not found"
attachment.error = "Asset not found!"
attachment.status = "assetNotFound"
// console.error('asset not found', asset)

return
}

Expand Down
21 changes: 16 additions & 5 deletions src/export/globCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { ExportProperties } from "src/models/export-properties"

import { globSync } from 'glob'
import { join, parse } from "path"
import { cpSync, existsSync, mkdirSync, stat, statSync } from "fs"
import { cpSync, existsSync, mkdirSync, statSync } from "fs"
import { Plugin } from "obsidian"
import { AttachmentLink } from "./get-markdown-attachments"
import { AttachmentLink, LinkType } from "./get-links-and-attachments"

export interface GlobMap { [glob: string]: Array<AttachmentLink> }

Expand Down Expand Up @@ -41,8 +41,11 @@ export async function copyGlob(fileExportProperties: ExportProperties, globStrin
count: 0,
newPath: toAbsolutePath,
originalPath: relativeFileName,
normalizedOriginalPath: relativeFileName,
status: 'success',
type: 'folder'
text: relativeFileName,
source: "globCopy",
linkType: LinkType.internal
})
}

Expand All @@ -53,16 +56,24 @@ export async function copyGlob(fileExportProperties: ExportProperties, globStrin
count: 1,
newPath: exportTargetDir,
originalPath: relativeFileName,
status: 'success'
status: 'success',
normalizedOriginalPath: relativeFileName,
text: relativeFileName,
source: "globCopy",
linkType: LinkType.internal
})
} catch(e){
console.error(e)
fileListExported.push({
count: 1,
newPath: toAbsolutePath,
originalPath: relativeFileName,
normalizedOriginalPath: relativeFileName,
status: 'error',
error: e.message
error: e.message,
text: relativeFileName,
source: "globCopy",
linkType: LinkType.internal
})
}
} else if (fileStats.isDirectory()){
Expand Down
70 changes: 50 additions & 20 deletions src/ui/stats-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getIcon } from "src/obsidian-api-helpers/get-icon";
const LINK_LISTS = [
'internalLinks',
'externalLinks',
'attachments',
'internalAttachments',
'internalAttachments',
'externalAttachments',
'headerAttachments'
Expand All @@ -28,6 +28,32 @@ export class StatsModal extends Modal {
contentEl.createEl("h1", { text: this.item.file?.path })

const content = contentEl.createDiv({ cls: 'content' })
this.linkStats(content)
this.globStats(content)
}


globStats(content: HTMLElement){
if (this.item.copyGlob){
content.createEl('h2', 'bopy raw files')
Object.keys(this.item.copyGlob).forEach((selector)=>{
const groupDiv = content.createDiv()
groupDiv.createEl('h3', { text: selector })

// @ts-ignore
if (this.item.copyGlob[selector] && this.item.copyGlob[selector].length){
// @ts-ignore
this.item.copyGlob[selector].forEach((link: AttachmentLink) => {
this.renderLink(link, groupDiv)
})
} else {
groupDiv.createSpan({text: 'no files found'})
}
})
}
}

linkStats(content: HTMLElement) {
LINK_LISTS.forEach((linkOrAttachmentGroupKey) => {
// @ts-ignore
if (this.item.linksAndAttachments && this.item.linksAndAttachments[linkOrAttachmentGroupKey]) {
Expand All @@ -38,31 +64,35 @@ export class StatsModal extends Modal {
groupDiv.createEl('h3', { text: linkOrAttachmentGroupKey })

linkGroup.forEach((link: AttachmentLink) => {
const linkDisplay = groupDiv.createDiv({
cls: link.error ? 'error link' : (link.newPath? 'success link' : 'link')
})
linkDisplay.createEl('a', {
text: link.text,
title: link.normalizedOriginalPath,
cls: 'title',
href: link.originalPath
})
linkDisplay.createSpan({ text: link.normalizedOriginalPath, cls: 'url'})
if (link.newPath) {
linkDisplay.createSpan({ text: `=> ${link.newPath}`, cls: 'replaced' })
}
if (link.error) {
linkDisplay.createDiv({ cls: 'error', text: link.error })
linkDisplay.prepend(getIcon('alert-triangle'));
} else if (link.newPath) {
linkDisplay.prepend(getIcon('check'));
}
this.renderLink(link, groupDiv)
})
}
}
})
}

renderLink(link: AttachmentLink, groupDiv: HTMLElement){
const linkDisplay = groupDiv.createDiv({
cls: link.error ? 'error link' : (link.newPath? 'success link' : 'link')
})
linkDisplay.createEl('a', {
text: link.text,
title: link.normalizedOriginalPath,
cls: 'title',
href: link.originalPath
})
linkDisplay.createSpan({ text: link.normalizedOriginalPath, cls: 'url'})
if (link.newPath) {
linkDisplay.createSpan({ text: `=> ${link.newPath}`, cls: 'replaced' })
}
if (link.error) {
linkDisplay.createDiv({ cls: 'error', text: link.error })
linkDisplay.prepend(getIcon('alert-triangle'));
} else if (link.newPath) {
linkDisplay.prepend(getIcon('check'));
}
}

onClose() {
this.contentEl.empty();
}
Expand Down
2 changes: 2 additions & 0 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export class BulkExporterView extends ItemView {
const setting = this.plugin.settings.items[selectedIndex]
await this.exporter.searchAndExport(setting)
}

await this.refresh()
}, (e) => {
error(e?.message || 'Something went wrong with the export, see log!')
this.settingsHeader.style.display = 'block';
Expand Down

0 comments on commit 9771e00

Please sign in to comment.