Skip to content

Commit

Permalink
compiler: fp fc yeah
Browse files Browse the repository at this point in the history
  • Loading branch information
julesvirallinen committed Sep 28, 2023
1 parent 9ea6ee7 commit c0cf8f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
38 changes: 19 additions & 19 deletions src/compiler/GardenPageCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ export class GardenPageCompiler {
async generateMarkdown(file: PublishFile): Promise<TCompiledFile> {
const assets: Assets = { images: [] };

const processedFrontmatter = file.getProcessedFrontmatter();

const fileText = await file.cachedRead();

if (file.getType() === "excalidraw") {
Expand All @@ -90,20 +88,25 @@ export class GardenPageCompiler {
];
}

let text = await this.convertFrontMatter(
fileText,
processedFrontmatter,
const COMPILE_STEPS: TCompilerStep[] = [
this.convertFrontMatter,
this.convertCustomFilters,
this.createBlockIDs,
this.removeObsidianComments,
this.convertDataViews,
this.convertLinksToFullPath,
this.createTranscludedText(0),
this.createSvgEmbeds,
];

const compiledText = await COMPILE_STEPS.reduce(
async (previousStep, currentStep) =>
currentStep(file, await previousStep),
Promise.resolve(fileText),
);
text = await this.convertCustomFilters(file, text);
text = await this.createBlockIDs(file, text);
text = await this.createTranscludedText(0)(file, text);
text = await this.convertDataViews(file, text);
text = await this.convertLinksToFullPath(file, text);
text = await this.removeObsidianComments(file, text);
text = await this.createSvgEmbeds(file, text);

const text_and_images = await this.convertImageLinks(
text,
compiledText,
file.getPath(),
);

Expand Down Expand Up @@ -173,16 +176,13 @@ export class GardenPageCompiler {
return text;
};

async convertFrontMatter(
text: string,
frontmatter: string,
): Promise<string> {
convertFrontMatter: TCompilerStep = (file, text) => {
const replaced = text.replace(FRONTMATTER_REGEX, (_match, _p1) => {
return frontmatter;
return file.getProcessedFrontmatter();
});

return replaced;
}
};

convertDataViews: TCompilerStep = async (file, text) => {
let replacedText = text;
Expand Down
15 changes: 13 additions & 2 deletions src/ui/PublishModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PublicationCenter from "./PublicationCenter.svelte";
import DiffView from "./DiffView.svelte";
import DigitalGardenSiteManager from "src/publisher/DigitalGardenSiteManager";
import * as Diff from "diff";
import { PublishFile } from "../publisher/PublishFile";

export class PublishModal {
modal: Modal;
Expand Down Expand Up @@ -51,11 +52,21 @@ export class PublishModal {
const remoteContent =
await this.siteManager.getNoteContent(notePath);
const localFile = this.vault.getAbstractFileByPath(notePath);
console.log(localFile);

const localPublishFile = new PublishFile({
file: localFile as TFile,
vault: this.vault,
compiler: this.publisher.compiler,
metadataCache: this.publisher.metadataCache,
settings: this.settings,
});

if (localFile instanceof TFile) {
const [localContent, _] =
await this.publisher.compiler.generateMarkdown(localFile);
await this.publisher.compiler.generateMarkdown(
localPublishFile,
);

const diff = Diff.diffLines(remoteContent, localContent);
let diffView: DiffView | undefined;
const diffModal = new Modal(this.modal.app);
Expand Down

0 comments on commit c0cf8f4

Please sign in to comment.