-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79ccb15
commit 89ec12f
Showing
8 changed files
with
184 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { MetadataCache, TFile, Vault } from "obsidian"; | ||
import { | ||
GardenPageCompiler, | ||
TCompiledFile, | ||
} from "../compiler/GardenPageCompiler"; | ||
import { | ||
FrontmatterCompiler, | ||
TFrontmatter, | ||
} from "../compiler/FrontmatterCompiler"; | ||
import DigitalGardenSettings from "../models/settings"; | ||
import { isPublishFrontmatterValid } from "./Validator"; | ||
|
||
interface IPublishFileProps { | ||
file: TFile; | ||
vault: Vault; | ||
compiler: GardenPageCompiler; | ||
metadataCache: MetadataCache; | ||
settings: DigitalGardenSettings; | ||
} | ||
|
||
export class PublishFile { | ||
file: TFile; | ||
compiler: GardenPageCompiler; | ||
vault: Vault; | ||
compiledFile?: TCompiledFile; | ||
metadataCache: MetadataCache; | ||
frontmatter: TFrontmatter; | ||
settings: DigitalGardenSettings; | ||
|
||
constructor({ | ||
file, | ||
compiler, | ||
metadataCache, | ||
vault, | ||
settings, | ||
}: IPublishFileProps) { | ||
this.compiler = compiler; | ||
this.metadataCache = metadataCache; | ||
this.file = file; | ||
this.settings = settings; | ||
this.vault = vault; | ||
this.frontmatter = this.getFrontmatter(); | ||
} | ||
|
||
async compile(): Promise<CompiledPublishFile> { | ||
const compiledFile = await this.compiler.generateMarkdown(this.file); | ||
|
||
return new CompiledPublishFile( | ||
{ | ||
file: this.file, | ||
compiler: this.compiler, | ||
metadataCache: this.metadataCache, | ||
vault: this.vault, | ||
settings: this.settings, | ||
}, | ||
compiledFile, | ||
); | ||
} | ||
|
||
shouldPublish(): boolean { | ||
return isPublishFrontmatterValid(this.frontmatter); | ||
} | ||
|
||
async getImageLinks() { | ||
const content = await this.cachedRead(); | ||
|
||
return this.compiler.extractImageLinks(content, this.file.path); | ||
} | ||
|
||
async cachedRead() { | ||
return this.vault.cachedRead(this.file); | ||
} | ||
|
||
getFrontmatter() { | ||
return this.metadataCache.getCache(this.file.path)?.frontmatter ?? {}; | ||
} | ||
|
||
getPath = () => this.file.path; | ||
getProcessedFrontmatter() { | ||
const frontmatterCompiler = new FrontmatterCompiler(this.settings); | ||
|
||
const metadata = | ||
this.metadataCache.getCache(this.file.path)?.frontmatter ?? {}; | ||
|
||
return frontmatterCompiler.getProcessedFrontMatter(this.file, metadata); | ||
} | ||
} | ||
|
||
export class CompiledPublishFile extends PublishFile { | ||
compiledFile: TCompiledFile; | ||
|
||
constructor(props: IPublishFileProps, compiledFile: TCompiledFile) { | ||
super(props); | ||
|
||
this.compiledFile = compiledFile; | ||
} | ||
|
||
getCompiledFile() { | ||
return this.compiledFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.