-
Notifications
You must be signed in to change notification settings - Fork 2
publishing: Allow setting target format #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { Notice, TFile } from "obsidian"; | ||
| import type AtmospherePlugin from "../main"; | ||
| import type { ContentFormat } from "../settings"; | ||
| import { createDocument, putDocument, getPublication, markdownToLeafletContent, stripMarkdown, markdownToPcktContent, buildDocumentUrl, resolveWikilinks } from "../lib"; | ||
| import { PublicationSelection, SelectPublicationModal } from "../components/selectPublicationModal"; | ||
| import { type ResourceUri, } from "@atcute/lexicons"; | ||
|
|
@@ -87,6 +88,17 @@ async function updateFrontMatter( | |
| }); | ||
| } | ||
|
|
||
| function normalizeFormat(raw: unknown): ContentFormat | undefined { | ||
| if (typeof raw !== "string") { | ||
| return undefined; | ||
| } | ||
| const trimmed = raw.trim().toLowerCase(); | ||
| if (trimmed === "leaflet" || trimmed === "pckt" || trimmed === "plaintext") { | ||
| return trimmed; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
|
|
||
| async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promise<{ record: SiteStandardDocument.Main; docUri?: ResourceUri }> { | ||
| const full = await plugin.app.vault.read(file); | ||
|
|
@@ -105,6 +117,7 @@ async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promi | |
| let path: string | undefined; | ||
| let tags: string[] | undefined; | ||
| let publishedAt: string | undefined; | ||
| let format: ContentFormat | undefined; | ||
| if (fm) { | ||
| pubUri = fm["atPublication"]; | ||
| docUri = fm["atDocument"] as ResourceUri; | ||
|
|
@@ -114,6 +127,7 @@ async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promi | |
| tags = fm["tags"] && Array.isArray(fm["tags"]) ? fm["tags"] : undefined; | ||
| publishedAt = fm["publishedAt"]; // Preserve existing if updating | ||
| } | ||
| format = normalizeFormat(fm?.["format"]); | ||
|
|
||
| if (!title && plugin.settings.publish.useFirstHeaderAsTitle) { | ||
| title = extractFirstH1(content); | ||
|
|
@@ -144,10 +158,20 @@ async function buildDocumentRecord(plugin: AtmospherePlugin, file: TFile): Promi | |
| let textContent = stripMarkdown(resolved); | ||
|
|
||
| let richContent: PubLeafletContent.Main | BlogPcktContent.Main | null = null; | ||
| const publicationFormat = pubUri ? normalizeFormat(plugin.settings.publicationFormats?.[pubUri]) : undefined; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here we are choosing format based on pub But If you try to use something like this in the settings (a leaflet pub mapped to pckt format) The mapping is overridden since the pub URL still contains leaflet. I'm aware that the pub url based selection is not great, and I intend to improve that. And I want to unblock you in the meantime.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't worry too much about blocking me! I didn't think about URI vs URL here |
||
| let contentFormat: ContentFormat = "plaintext"; | ||
| if (pub?.url.contains("leaflet.pub")) { | ||
| richContent = await markdownToLeafletContent(resolved) | ||
| contentFormat = "leaflet"; | ||
| } else if (pub?.url.contains("pckt.blog")) { | ||
| richContent = markdownToPcktContent(resolved) | ||
| contentFormat = "pckt"; | ||
| } else { | ||
| contentFormat = format ?? publicationFormat ?? "plaintext"; | ||
| } | ||
|
|
||
| if (contentFormat === "leaflet") { | ||
| richContent = await markdownToLeafletContent(resolved); | ||
| } else if (contentFormat === "pckt") { | ||
| richContent = markdownToPcktContent(resolved); | ||
| } | ||
|
|
||
| let record = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,11 @@ export interface AtProtoSettings { | |
| publish: { | ||
| useFirstHeaderAsTitle: boolean; | ||
| }; | ||
| publicationFormats: Record<string, ContentFormat>; | ||
| } | ||
|
|
||
| export type ContentFormat = "leaflet" | "pckt" | "plaintext"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove plaintext as an option, because the plaintext is always set for |
||
|
|
||
| export const DEFAULT_SETTINGS: AtProtoSettings = { | ||
| clipDir: "AtmosphereClips", | ||
| bookmarks: { | ||
|
|
@@ -24,6 +27,7 @@ export const DEFAULT_SETTINGS: AtProtoSettings = { | |
| publish: { | ||
| useFirstHeaderAsTitle: false, | ||
| }, | ||
| publicationFormats: {}, | ||
| }; | ||
|
|
||
| export class SettingTab extends PluginSettingTab { | ||
|
|
@@ -164,5 +168,6 @@ export class SettingTab extends PluginSettingTab { | |
| await this.plugin.saveSettings(); | ||
| }) | ||
| ); | ||
|
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here, format property from the frontmatter is not respected if the publication has URL that matches leaflet or pckt.
I've thought that mapping a publication to a content type format might be better done via some type of UI interaction. But for now I think a frontmatter property is a good option.
Let's update this PR to remove the publicationFormats setting since:
If the property is set, we should not even bother checking the pub url and only use the property's format.
In the future I think we'd want to use full lexicon name, but the short leaflet and pckt are good for now
However, lets rename the property to be
docContentFormat