Browse Source

bug-fixes:

wiki pages missing prepared text
master
Silberengel 7 days ago
parent
commit
b835bb6157
  1. 26
      src/main.ts
  2. 8
      src/metadataManager.ts

26
src/main.ts

@ -241,15 +241,31 @@ export default class ScriptoriumPlugin extends Plugin {
// Continue anyway - file was created // Continue anyway - file was created
} }
// For .adoc files, ensure file is visible in explorer but don't auto-open // For .adoc files, try to auto-open after a longer delay to allow obsidian-asciidoc plugin to initialize
if (file.extension === "adoc" || file.extension === "asciidoc") { if (file.extension === "adoc" || file.extension === "asciidoc") {
log(`AsciiDoc file created: ${file.path}`); log(`AsciiDoc file created: ${file.path}`);
// File should be visible in Obsidian's file explorer automatically // Wait longer for obsidian-asciidoc plugin to be ready
// since we used vault.create(). The file explorer will refresh automatically. await new Promise(resolve => setTimeout(resolve, 500));
// We don't auto-open to prevent crashes (obsidian-asciidoc plugin handles opening)
new Notice(`Created ${filename} in ${folderPath}. Install obsidian-asciidoc plugin to edit in Obsidian.`); try {
log(`Attempting to open AsciiDoc file: ${file.path}`);
const leaf = this.app.workspace.getMostRecentLeaf();
if (leaf && leaf.view) {
await leaf.openFile(file, { active: true });
log("AsciiDoc file opened successfully");
new Notice(`Created and opened ${filename}`);
} else {
const newLeaf = this.app.workspace.getLeaf("tab");
await newLeaf.openFile(file, { active: true });
log("AsciiDoc file opened in new leaf");
new Notice(`Created and opened ${filename}`);
}
} catch (error: any) {
logError("Error opening AsciiDoc file", error);
// Don't show error to user - file was created successfully
new Notice(`Created ${filename} in ${folderPath}. You may need to open it manually.`);
}
} else { } else {
// Open the new file in Obsidian workspace (use active leaf or create new) // Open the new file in Obsidian workspace (use active leaf or create new)
// Use a small delay to ensure file is fully created before opening // Use a small delay to ensure file is fully created before opening

8
src/metadataManager.ts

@ -365,10 +365,14 @@ export async function writeMetadata(
const { body } = parseMarkdownFrontmatter(currentContent); const { body } = parseMarkdownFrontmatter(currentContent);
const frontmatter = formatMarkdownFrontmatter(metadata); const frontmatter = formatMarkdownFrontmatter(metadata);
// If body is empty or only whitespace, add default content // If body is empty, only whitespace, or only contains a single header line, add default content
const trimmedBody = body.trim(); const trimmedBody = body.trim();
// Check if body only contains a single header line (e.g., "# Title" or "## Title")
// Split by newlines and filter out empty lines to count non-empty lines
const nonEmptyLines = trimmedBody.split('\n').filter(line => line.trim().length > 0);
const isOnlyHeader = trimmedBody && nonEmptyLines.length === 1 && /^#+\s+.+$/.test(nonEmptyLines[0]);
let finalBody = body; let finalBody = body;
if (!trimmedBody || trimmedBody.length === 0) { if (!trimmedBody || trimmedBody.length === 0 || isOnlyHeader) {
// For kind 1, just add placeholder text (no header) // For kind 1, just add placeholder text (no header)
if (metadata.kind === 1) { if (metadata.kind === 1) {
finalBody = `place your content here\n\n---\n\n**How to use this app:**\n1. Edit your content above\n2. Click the Nostr menu button (lightning bolt icon ⚡) in the left sidebar\n3. Select "Create Nostr events" to create and sign events\n4. Select "Publish events to relays" to publish to relays`; finalBody = `place your content here\n\n---\n\n**How to use this app:**\n1. Edit your content above\n2. Click the Nostr menu button (lightning bolt icon ⚡) in the left sidebar\n3. Select "Create Nostr events" to create and sign events\n4. Select "Publish events to relays" to publish to relays`;

Loading…
Cancel
Save