Skip to content

Commit

Permalink
publisher: note / image path to const
Browse files Browse the repository at this point in the history
  • Loading branch information
julesvirallinen committed Sep 27, 2023
1 parent 133e900 commit 4a1357b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/publisher/DigitalGardenSiteManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Octokit } from "@octokit/core";
import { Base64 } from "js-base64";
import type DigitalGardenPluginInfo from "../models/pluginInfo";
import { IMAGE_PATH_BASE, NOTE_PATH_BASE } from "./Publisher";

export interface PathRewriteRule {
from: string;
Expand Down Expand Up @@ -146,7 +147,7 @@ export default class DigitalGardenSiteManager {
{
owner: this.settings.githubUserName,
repo: this.settings.githubRepo,
path: "src/site/notes/" + path,
path: NOTE_PATH_BASE + path,
},
);

Expand Down Expand Up @@ -175,14 +176,14 @@ export default class DigitalGardenSiteManager {

const notes: Array<{ path: string; sha: string }> = files.filter(
(x: { path: string; type: string }) =>
x.path.startsWith("src/site/notes/") &&
x.path.startsWith(NOTE_PATH_BASE) &&
x.type === "blob" &&
x.path !== "src/site/notes/notes.json",
x.path !== `${NOTE_PATH_BASE}notes.json`,
);
const hashes: Record<string, string> = {};

for (const note of notes) {
const vaultPath = note.path.replace("src/site/notes/", "");
const vaultPath = note.path.replace(NOTE_PATH_BASE, "");
hashes[vaultPath] = note.sha;
}

Expand All @@ -208,14 +209,12 @@ export default class DigitalGardenSiteManager {

const images: Array<{ path: string; sha: string }> = files.filter(
(x: { path: string; type: string }) =>
x.path.startsWith("src/site/img/user/") && x.type === "blob",
x.path.startsWith(IMAGE_PATH_BASE) && x.type === "blob",
);
const hashes: Record<string, string> = {};

for (const img of images) {
const vaultPath = decodeURI(
img.path.replace("src/site/img/user/", ""),
);
const vaultPath = decodeURI(img.path.replace(IMAGE_PATH_BASE, ""));
hashes[vaultPath] = img.sha;
}

Expand Down
10 changes: 7 additions & 3 deletions src/publisher/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export interface MarkedForPublishing {
notes: TFile[];
images: string[];
}

export const IMAGE_PATH_BASE = "src/site/img/user/";
export const NOTE_PATH_BASE = "src/site/notes/";

/**
* Prepares files to be published and publishes them to Github
*/
Expand Down Expand Up @@ -70,13 +74,13 @@ export default class Publisher {
}

async deleteNote(vaultFilePath: string) {
const path = `src/site/notes/${vaultFilePath}`;
const path = `${NOTE_PATH_BASE}${vaultFilePath}`;

return await this.delete(path);
}

async deleteImage(vaultFilePath: string) {
const path = `src/site/img/user/${vaultFilePath}`;
const path = `${IMAGE_PATH_BASE}${vaultFilePath}`;

return await this.delete(path);
}
Expand Down Expand Up @@ -230,7 +234,7 @@ export default class Publisher {

async uploadText(filePath: string, content: string) {
content = Base64.encode(content);
const path = `src/site/notes/${filePath}`;
const path = `${NOTE_PATH_BASE}${filePath}`;
await this.uploadToGithub(path, content);
}

Expand Down

0 comments on commit 4a1357b

Please sign in to comment.