Browse Source

updated docs

master
Silberengel 1 week ago
parent
commit
d71b630a89
  1. 194
      README.md
  2. 14
      src/ui/metadataReminderModal.ts
  3. 289
      start-obsidian.sh

194
README.md

@ -3,118 +3,107 @@
An Obsidian plugin for creating, editing, and publishing Nostr document events directly from your vault. An Obsidian plugin for creating, editing, and publishing Nostr document events directly from your vault.
**Author**: Silberengel **Author**: Silberengel
**Homepage of our development project**: https://gitcitadel.com **Homepage**: https://gitcitadel.com
**Happy to receive Bitcoin-tips to our Lightning wallet**: gitcitadel@getalby.com **Lightning tips**: gitcitadel@getalby.com
## Features ## Features
- Multiple event kinds: Markdown (1, 11, 30023, 30817) and AsciiDoc (30040, 30041, 30818) formats - **Multiple event kinds**: Markdown (1, 11, 30023, 30817) and AsciiDoc (30040, 30041, 30818)
- Automatic book/publication parsing into nested 30040/30041 structures - **Automatic structure parsing**: AsciiDoc documents with headers are parsed into nested 30040/30041 event hierarchies
- Metadata stored in Markdown frontmatter and AsciiDoc header attributes - **Metadata in files**: Metadata stored directly in Markdown frontmatter or AsciiDoc header attributes
- Structure preview before creating events - **Two-step workflow**: Create/sign events separately from publishing to relays
- Two-step workflow: create/sign events separately from publishing - **Automatic relay management**: Fetch relay lists (kind 10002) with AUTH support
- Automatic relay list fetching (kind 10002) with AUTH support
- NIP-54 compliant d-tag normalization
## Installation ## Quick Start
### Quick Start ### Installation
Use the startup script to build, install, and launch Obsidian:
```bash ```bash
# First run (path required) # First run (vault path required)
./start-obsidian.sh ~/Documents/MyVault ./start-obsidian.sh ~/Documents/MyVault
# Subsequent runs (path is saved) # Subsequent runs (path saved)
./start-obsidian.sh ./start-obsidian.sh
``` ```
The script automatically: The script automatically installs dependencies, builds the plugin, and starts Obsidian.
- Installs npm dependencies
- Builds and installs the plugin
- Installs and enables obsidian-asciidoc (required for `.adoc` files)
- Starts Obsidian with console logging
**Generate a new Nostr key:**
```bash
./start-obsidian.sh --generate-key
```
Add the shown export command to your shell profile (`~/.bashrc`, `~/.zshrc`, etc.).
### Manual Installation
1. Clone repo → `npm install``npm run build`
2. Copy `main.js` and `manifest.json` to `.obsidian/plugins/scriptorium-obsidian/`
3. Enable in Obsidian Settings → Community Plugins
4. Install [obsidian-asciidoc](https://github.com/dzruyk/obsidian-asciidoc) plugin (required for `.adoc` files)
## Setup
### Private Key
The plugin only loads keys from the `SCRIPTORIUM_OBSIDIAN_KEY` environment variable:
```bash
# Set in terminal
export SCRIPTORIUM_OBSIDIAN_KEY="nsec1..."
# Make permanent (add to ~/.bashrc or ~/.zshrc) ### Setup
echo 'export SCRIPTORIUM_OBSIDIAN_KEY="nsec1..."' >> ~/.bashrc
```
**Important:** Launch Obsidian from the terminal where the variable is set, or use the startup script. Desktop shortcuts won't have access to the variable. 1. **Generate a Nostr key** (if needed):
```bash
./start-obsidian.sh --generate-key
```
Add the shown export command to your shell profile (`~/.bashrc`, `~/.zshrc`, etc.).
### Relays 2. **Set your private key**:
```bash
export SCRIPTORIUM_OBSIDIAN_KEY="nsec1..."
```
1. Open Settings → Scriptorium Nostr 3. **Configure relays**:
2. Click "Fetch" to get your relay list from Nostr relays - Open Obsidian Settings → Scriptorium Nostr
3. Relays are automatically fetched from default relays - Click "Fetch" to get your relay list
## Usage ## Usage
### Creating Events ### Creating Events
1. Open a Markdown or AsciiDoc file 1. Open a Markdown or AsciiDoc file
2. Run: `Create Nostr Events` 2. Run command: **Create Nostr Events**
3. Events are created, signed, and saved to `{filename}_events.jsonl` 3. A reminder modal will prompt you to update metadata
4. Update metadata in the file (see Metadata section below)
5. Click "OK" in the modal
6. Events are created, signed, and saved to `{filename}_events.jsonl`
### Publishing ### Publishing Events
1. Ensure events exist (`{filename}_events.jsonl`) 1. Ensure events exist (`{filename}_events.jsonl`)
2. Run: `Publish Events to Relays` 2. Run command: **Publish Events to Relays**
3. Events publish to all configured write relays 3. Events publish to all configured write relays
### Other Commands ### Other Commands
- `Edit Metadata` - Open metadata form for current file - **Edit Metadata** - Open metadata editor for current file
- `Preview Document Structure` - Show event hierarchy (AsciiDoc only) - **Preview Document Structure** - Show event hierarchy (AsciiDoc structured documents only)
- **New Nostr Document** - Create a new document with metadata template
## File Formats ## File Formats
- **Markdown** (`.md`): Kinds 1, 11, 30023, 30817 ### Markdown Files (`.md`)
- **AsciiDoc** (`.adoc`): Kinds 30040, 30041, 30818
- **Structured AsciiDoc** (starts with `= Title`): Kind 30040 with nested 30041 events
### Metadata
Metadata is stored directly in the file: Supported event kinds: **1**, **11**, **30023**, **30817**
- **Markdown files**: YAML frontmatter at the top of the file (between `---` markers)
- **AsciiDoc files**: Header attributes (lines starting with `:key: value`) after the title
When publishing, metadata is automatically stripped from the content before creating events. Metadata is stored in YAML frontmatter at the top of the file:
Example Markdown frontmatter:
```yaml ```yaml
--- ---
kind: 30023 kind: 30023
title: "My Article" title: "My Article"
author: "Author Name" author: "Author Name"
summary: "Article summary" summary: "Article summary"
image: "https://example.com/image.jpg"
topics: "bitcoin, nostr"
published_at: "1234567890"
--- ---
``` ```
Example AsciiDoc attributes: ### AsciiDoc Files (`.adoc`)
Supported event kinds: **30040**, **30041**, **30818**
**Simple AsciiDoc** (kind 30818):
```asciidoc
= Wiki Page Title
:kind: 30818
:author: Author Name
:summary: Page description
:image: https://example.com/image.jpg
:topics: bitcoin, nostr
```
**Structured AsciiDoc** (kind 30040 with nested 30041):
```asciidoc ```asciidoc
= Book Title = Book Title
@ -122,8 +111,77 @@ Example AsciiDoc attributes:
:author: Author Name :author: Author Name
:type: book :type: book
:summary: Book description :summary: Book description
:collection_id: my-collection
:version_tag: v1
== Chapter 1
Chapter content here...
=== Section 1.1
Section content...
``` ```
When publishing, metadata is automatically stripped from content before creating events.
## Event Kinds
| Kind | Format | Description | Title Required |
|------|--------|-------------|---------------|
| 1 | Markdown | Normal note | No |
| 11 | Markdown | Discussion thread OP | Yes |
| 30023 | Markdown | Long-form article | Yes |
| 30040 | AsciiDoc | Publication index | Yes |
| 30041 | AsciiDoc | Publication content | Yes |
| 30817 | Markdown | Wiki page | Yes |
| 30818 | AsciiDoc | Wiki page | Yes |
### Stand-alone vs Nested 30041
- **Stand-alone 30041**: Uses NKBIP-01 tags (d, title, image, summary, published_at, topics)
- **Nested 30041** (under 30040): Uses NKBIP-08 tags (inherits collection_id, version_tag from parent)
## Metadata Fields
All predefined metadata fields are shown in frontmatter/attributes with placeholder descriptions. Remove or update placeholders you don't need. Placeholder values are automatically skipped when creating events.
### Common Fields
- `kind` - Event kind (required)
- `title` - Document title (required for all except kind 1)
- `author` - Author name
- `summary` - Brief description
- `topics` - Comma-separated topics (available for all event kinds)
- `image` - Image URL (available for 30023, 30040, 30041, 30817, 30818)
### Kind-Specific Fields
**30023 (Article)**:
- `published_at` - Unix timestamp
**30040 (Publication Index)**:
- `type` - Publication type (book, illustrated, magazine, documentation, academic, blog)
- `version` - Version or edition
- `published_on` - Publication date
- `published_by` - Publisher
- `source` - Source URL
- `auto_update` - Auto-update behavior (yes, ask, no)
- `collection_id` - NKBIP-08 collection identifier
- `version_tag` - NKBIP-08 version identifier
**30041 (Publication Content)**:
- Stand-alone: Same as 30023 (image, summary, published_at, topics)
- Nested: NKBIP-08 tags (collection_id, title_id, chapter_id, section_id, version_tag)
## Manual Installation
1. Clone repository
2. Run `npm install && npm run build`
3. Copy `main.js` and `manifest.json` to `.obsidian/plugins/scriptorium-obsidian/`
4. Enable in Obsidian Settings → Community Plugins
5. Install [obsidian-asciidoc](https://github.com/dzruyk/obsidian-asciidoc) plugin (required for `.adoc` files)
## Development ## Development
```bash ```bash

14
src/ui/metadataReminderModal.ts

@ -23,7 +23,7 @@ export class MetadataReminderModal extends Modal {
const infoDiv = contentEl.createDiv({ cls: "scriptorium-reminder-info" }); const infoDiv = contentEl.createDiv({ cls: "scriptorium-reminder-info" });
infoDiv.createEl("p", { infoDiv.createEl("p", {
text: "Please update the metadata in your file before creating events:", text: "Before creating events, update the metadata in your file:",
}); });
const list = infoDiv.createEl("ul"); const list = infoDiv.createEl("ul");
@ -33,25 +33,25 @@ export class MetadataReminderModal extends Modal {
if (requiresTitle) { if (requiresTitle) {
const titleItem = list.createEl("li"); const titleItem = list.createEl("li");
titleItem.createEl("strong", { text: "Title is mandatory" }); titleItem.createEl("strong", { text: "Title is required" });
titleItem.createEl("span", { text: " - Update the title field in the frontmatter/attributes" }); titleItem.createEl("span", { text: " - Set the title field in frontmatter/attributes" });
} }
list.createEl("li", { list.createEl("li", {
text: "Review all metadata fields in the frontmatter (Markdown) or header attributes (AsciiDoc)", text: "Review all metadata fields (shown with placeholder descriptions)",
}); });
list.createEl("li", { list.createEl("li", {
text: "Remove or update any placeholder descriptions you don't want to use", text: "Remove placeholders you don't need, or replace them with actual values",
}); });
list.createEl("li", { list.createEl("li", {
text: "Add any custom tags you need", text: "Add custom tags if needed",
}); });
const noteDiv = contentEl.createDiv({ cls: "scriptorium-reminder-note" }); const noteDiv = contentEl.createDiv({ cls: "scriptorium-reminder-note" });
noteDiv.createEl("p", { noteDiv.createEl("p", {
text: "Note: Placeholder values (descriptions) will be automatically skipped when creating events.", text: "Note: Placeholder descriptions are automatically skipped when creating events.",
}); });
// Buttons // Buttons

289
start-obsidian.sh

@ -9,65 +9,37 @@ set -e # Exit on error
# Function to show help # Function to show help
show_help() { show_help() {
cat << EOF cat << EOF
Scriptorium Obsidian Plugin - Startup Script Scriptorium Nostr - Obsidian Plugin Startup Script
USAGE: USAGE:
$0 [OPTIONS] [path-to-obsidian-vault] $0 [OPTIONS] [vault-path]
OPTIONS: OPTIONS:
-h, --help Show this help message and exit -h, --help Show this help message
--generate-key Generate a new Nostr private key --generate-key Generate a new Nostr private key
The key will be shown for you to save as an environment variable
(most secure option - hides key from GUI)
ARGUMENTS: ARGUMENTS:
path-to-obsidian-vault vault-path Path to your Obsidian vault folder
Path to your Obsidian vault (the folder containing .obsidian) Required on first run, optional afterwards
Required on first run. Optional on subsequent runs.
Note: The .obsidian folder may be hidden in your file manager.
EXAMPLES: EXAMPLES:
# First run (path required): $0 ~/Documents/MyVault # First run
$0 ~/Documents/MyVault $0 # Use saved vault path
$0 --generate-key # Generate new Nostr key
# Subsequent runs (uses saved path): $0 --help # Show this help
$0
WHAT THIS SCRIPT DOES:
# Change to a different vault: 1. Installs npm dependencies (if needed)
$0 ~/Documents/NewVault 2. Builds the Scriptorium plugin
3. Installs plugin to your vault
# Generate a new Nostr private key: 4. Installs obsidian-asciidoc plugin (for .adoc files)
$0 --generate-key [vault-path] 5. Starts Obsidian with console logging
# Show help:
$0 --help
DESCRIPTION:
This script will:
1. Install npm dependencies (if needed)
2. Build the Scriptorium plugin
3. Install it to your Obsidian vault's plugin folder
4. Install and enable the obsidian-asciidoc plugin (required for .adoc files)
5. Start Obsidian with console logging enabled
Note: The obsidian-asciidoc plugin is required for this plugin to work properly
with .adoc files. It will be installed and enabled automatically.
On first run, you must provide the vault path. The path will be saved
to .scriptorium-vault-path for future use.
If the saved path becomes invalid (vault moved/deleted), you'll be
prompted to provide a new path.
The obsidian-asciidoc plugin is recommended for editing .adoc files
in Obsidian without crashes. It provides proper syntax highlighting
and editing support.
NOTES: NOTES:
- The vault path is the folder containing the .obsidian directory • Vault path is saved after first run
- The .obsidian folder may be hidden in your file manager (enable "Show hidden files") • obsidian-asciidoc is installed automatically
- Plugin logs will appear in this terminal • Plugin logs appear in this terminal
- Press Ctrl+C to stop Obsidian • Press Ctrl+C to stop Obsidian
EOF EOF
exit 0 exit 0
} }
@ -185,22 +157,13 @@ NODE_SCRIPT
echo "Generated new Nostr key:" echo "Generated new Nostr key:"
echo " Public key (npub): $npub" echo " Public key (npub): $npub"
echo "" echo ""
echo "To use this key, set it as an environment variable:" echo "To use this key, add to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo "" echo ""
echo " export SCRIPTORIUM_OBSIDIAN_KEY=\"$nsec\"" echo " export SCRIPTORIUM_OBSIDIAN_KEY=\"$nsec\""
echo "" echo ""
echo "Add this line to your shell profile (~/.bashrc, ~/.zshrc, etc.) to make it permanent:" echo "Then restart your shell or run: source ~/.bashrc"
echo " export SCRIPTORIUM_OBSIDIAN_KEY=\"$nsec\""
echo ""
echo "Then launch Obsidian from that terminal (or restart your shell) to use the key, by typing 'obsidian' or './start-obsidian.sh'."
echo ""
echo "Note: The private key is hidden from the GUI for security. Only the public key (npub) is shown."
echo "To view the private key, you can use the following command:"
echo "" echo ""
echo " echo $nsec" echo "⚠ Keep your private key secure! Do not share it with anyone."
echo ""
echo "This will show the private key in clear text."
echo "Remember: The private key is only visible in the terminal and will not be available, unless you save it as an environment variable. Do not share it with anyone!"
} }
# If generating key, handle it separately (no vault path needed) # If generating key, handle it separately (no vault path needed)
@ -231,9 +194,8 @@ if [ -n "$1" ]; then
# Validate provided path # Validate provided path
if ! is_valid_vault_path "$VAULT_PATH"; then if ! is_valid_vault_path "$VAULT_PATH"; then
echo "Error: The provided path does not appear to be valid: $VAULT_PATH" echo "Error: Invalid vault path: $VAULT_PATH"
echo "Please provide a valid path to your Obsidian vault" echo "Please provide a valid path to your Obsidian vault folder"
echo "Note: The .obsidian folder may be hidden in your file manager."
exit 1 exit 1
fi fi
@ -252,28 +214,20 @@ else
else else
echo "Error: Saved vault path is no longer valid: $SAVED_PATH" echo "Error: Saved vault path is no longer valid: $SAVED_PATH"
echo "" echo ""
echo "The vault may have been moved or deleted. Please provide a new vault path:" echo "Please provide a new vault path:"
echo "" echo " $0 ~/Documents/MyVault"
echo "Usage: $0 <path-to-obsidian-vault>"
echo "Example: $0 ~/Documents/MyVault"
echo "" echo ""
echo "Note: The .obsidian folder may be hidden in your file manager." echo "Run '$0 --help' for more information"
echo "For more information, run: $0 --help"
exit 1 exit 1
fi fi
else else
echo "Error: No vault path provided and no saved path found" echo "Error: No vault path provided"
echo ""
echo "This appears to be your first run. Please provide the path to your Obsidian vault:"
echo "" echo ""
echo "Usage: $0 <path-to-obsidian-vault>" echo "First run requires a vault path:"
echo "Example: $0 ~/Documents/MyVault" echo " $0 ~/Documents/MyVault"
echo "" echo ""
echo "The vault path is the folder containing the .obsidian directory." echo "The path will be saved for future runs."
echo "Note: The .obsidian folder may be hidden in your file manager (enable 'Show hidden files')." echo "Run '$0 --help' for more information"
echo "After the first run, the path will be saved and you won't need to provide it again."
echo ""
echo "For more information, run: $0 --help"
exit 1 exit 1
fi fi
fi fi
@ -295,38 +249,23 @@ echo "[Scriptorium] Plugin folder: $PLUGIN_FOLDER"
# Check if npm dependencies need to be installed # Check if npm dependencies need to be installed
if [ ! -d "node_modules" ] || [ "package.json" -nt "node_modules" ]; then if [ ! -d "node_modules" ] || [ "package.json" -nt "node_modules" ]; then
echo "[Scriptorium] Installing npm dependencies..." echo "Installing dependencies..."
npm install npm install --silent
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Error: npm install failed" echo "Error: npm install failed"
exit 1 exit 1
fi fi
echo "[Scriptorium] Dependencies installed successfully" echo "✓ Dependencies installed"
else else
echo "[Scriptorium] Dependencies are up to date" echo "✓ Dependencies up to date"
fi fi
# Create .obsidian folder if it doesn't exist # Create necessary directories
if [ ! -d "$OBSIDIAN_FOLDER" ]; then mkdir -p "$PLUGIN_FOLDER"
echo "[Scriptorium] Creating .obsidian folder..."
mkdir -p "$OBSIDIAN_FOLDER"
fi
# Create plugins folder if it doesn't exist
if [ ! -d "${OBSIDIAN_FOLDER}/plugins" ]; then
echo "[Scriptorium] Creating plugins folder..."
mkdir -p "${OBSIDIAN_FOLDER}/plugins"
fi
# Create plugin directory if it doesn't exist
if [ ! -d "$PLUGIN_FOLDER" ]; then
echo "[Scriptorium] Creating plugin directory..."
mkdir -p "$PLUGIN_FOLDER"
fi
# Build the plugin # Build the plugin
echo "[Scriptorium] Building plugin..." echo "Building plugin..."
npm run build npm run build --silent 2>&1 | grep -v "^$" || true
# Check if build was successful # Check if build was successful
if [ ! -f "main.js" ] || [ ! -f "manifest.json" ]; then if [ ! -f "main.js" ] || [ ! -f "manifest.json" ]; then
@ -334,41 +273,10 @@ if [ ! -f "main.js" ] || [ ! -f "manifest.json" ]; then
exit 1 exit 1
fi fi
# Function to check if file needs to be copied # Copy plugin files
needs_copy() { cp "main.js" "${PLUGIN_FOLDER}/main.js"
local source_file="$1" cp "manifest.json" "${PLUGIN_FOLDER}/manifest.json"
local dest_file="$2" echo "✓ Plugin installed"
# If destination doesn't exist, we need to copy
if [ ! -f "$dest_file" ]; then
return 0 # true - needs copy
fi
# If source is newer than destination, we need to copy
if [ "$source_file" -nt "$dest_file" ]; then
return 0 # true - needs copy
fi
return 1 # false - no copy needed
}
# Copy main.js if needed
if needs_copy "main.js" "${PLUGIN_FOLDER}/main.js"; then
echo "[Scriptorium] Copying main.js to plugin folder..."
cp "main.js" "${PLUGIN_FOLDER}/main.js"
else
echo "[Scriptorium] main.js is up to date, skipping copy"
fi
# Copy manifest.json if needed
if needs_copy "manifest.json" "${PLUGIN_FOLDER}/manifest.json"; then
echo "[Scriptorium] Copying manifest.json to plugin folder..."
cp "manifest.json" "${PLUGIN_FOLDER}/manifest.json"
else
echo "[Scriptorium] manifest.json is up to date, skipping copy"
fi
echo "[Scriptorium] Plugin installed successfully!"
# Function to enable a plugin in Obsidian # Function to enable a plugin in Obsidian
enable_plugin() { enable_plugin() {
@ -382,7 +290,6 @@ enable_plugin() {
# Check if plugin is already enabled # Check if plugin is already enabled
if grep -q "\"$plugin_id\"" "$plugins_json" 2>/dev/null; then if grep -q "\"$plugin_id\"" "$plugins_json" 2>/dev/null; then
echo "[Scriptorium] Plugin $plugin_id is already enabled"
return 0 return 0
fi fi
@ -408,10 +315,8 @@ if (!plugins.includes('${plugin_id}')) {
console.log('Enabled plugin: ${plugin_id}'); console.log('Enabled plugin: ${plugin_id}');
} }
NODE_SCRIPT NODE_SCRIPT
if [ $? -eq 0 ]; then if [ $? -ne 0 ]; then
echo "[Scriptorium] Enabled plugin: $plugin_id" echo "Warning: Could not enable plugin $plugin_id automatically"
else
echo "[Scriptorium] Warning: Could not enable plugin $plugin_id automatically"
fi fi
elif command -v python3 &> /dev/null; then elif command -v python3 &> /dev/null; then
# Fallback to Python # Fallback to Python
@ -433,124 +338,92 @@ if plugin_id not in plugins:
json.dump(plugins, f, indent=2) json.dump(plugins, f, indent=2)
print(f'Enabled plugin: {plugin_id}') print(f'Enabled plugin: {plugin_id}')
PYTHON_SCRIPT PYTHON_SCRIPT
if [ $? -eq 0 ]; then if [ $? -ne 0 ]; then
echo "[Scriptorium] Enabled plugin: $plugin_id" echo "Warning: Could not enable plugin $plugin_id automatically"
else
echo "[Scriptorium] Warning: Could not enable plugin $plugin_id automatically"
fi fi
else else
echo "[Scriptorium] Warning: Node.js or Python3 required to auto-enable plugins" echo "Warning: Node.js or Python3 required to auto-enable plugins"
echo "[Scriptorium] Please enable $plugin_id manually in Obsidian settings" echo "Please enable $plugin_id manually in Obsidian settings"
fi fi
} }
# Enable scriptorium-obsidian plugin # Enable scriptorium-obsidian plugin
echo "[Scriptorium] Enabling scriptorium-obsidian plugin..." enable_plugin "scriptorium-obsidian" > /dev/null 2>&1
enable_plugin "scriptorium-obsidian"
# Install obsidian-asciidoc plugin (required for .adoc file support) # Install obsidian-asciidoc plugin (required for .adoc file support)
ASCIIDOC_PLUGIN_DIR="${OBSIDIAN_FOLDER}/plugins/obsidian-asciidoc" ASCIIDOC_PLUGIN_DIR="${OBSIDIAN_FOLDER}/plugins/obsidian-asciidoc"
ASCIIDOC_PLUGIN_REPO="https://github.com/dzruyk/obsidian-asciidoc.git" ASCIIDOC_PLUGIN_REPO="https://github.com/dzruyk/obsidian-asciidoc.git"
echo "[Scriptorium] Installing obsidian-asciidoc plugin (required for .adoc files)..." echo "Installing obsidian-asciidoc plugin..."
if [ -d "$ASCIIDOC_PLUGIN_DIR" ]; then if [ -d "$ASCIIDOC_PLUGIN_DIR" ]; then
echo "[Scriptorium] obsidian-asciidoc plugin already exists, updating..."
cd "$ASCIIDOC_PLUGIN_DIR" cd "$ASCIIDOC_PLUGIN_DIR"
if [ -d ".git" ]; then if [ -d ".git" ]; then
git pull || echo "[Scriptorium] Warning: Could not update plugin (git pull failed)" git pull --quiet 2>/dev/null || true
# Rebuild after update
if [ -f "package.json" ]; then if [ -f "package.json" ]; then
echo "[Scriptorium] Rebuilding obsidian-asciidoc plugin..." npm install --silent > /dev/null 2>&1 && npm run build --silent > /dev/null 2>&1 || true
npm install && npm run build || {
echo "[Scriptorium] Warning: Could not rebuild obsidian-asciidoc plugin"
}
fi fi
else
echo "[Scriptorium] Warning: Plugin directory exists but is not a git repository"
fi fi
cd "$SCRIPT_DIR" cd "$SCRIPT_DIR"
# Ensure plugin is enabled
ASCIIDOC_PLUGIN_ID=$(node -e "const m=require('${ASCIIDOC_PLUGIN_DIR}/manifest.json'); console.log(m.id)" 2>/dev/null || echo "obsidian-asciidoc") ASCIIDOC_PLUGIN_ID=$(node -e "const m=require('${ASCIIDOC_PLUGIN_DIR}/manifest.json'); console.log(m.id)" 2>/dev/null || echo "obsidian-asciidoc")
enable_plugin "$ASCIIDOC_PLUGIN_ID" enable_plugin "$ASCIIDOC_PLUGIN_ID" > /dev/null 2>&1
echo "✓ obsidian-asciidoc plugin ready"
else else
echo "[Scriptorium] Cloning obsidian-asciidoc plugin..."
if command -v git &> /dev/null; then if command -v git &> /dev/null; then
git clone "$ASCIIDOC_PLUGIN_REPO" "$ASCIIDOC_PLUGIN_DIR" || { git clone --quiet "$ASCIIDOC_PLUGIN_REPO" "$ASCIIDOC_PLUGIN_DIR" 2>/dev/null || {
echo "[Scriptorium] Error: Could not clone obsidian-asciidoc plugin" echo "Error: Could not clone obsidian-asciidoc plugin"
echo "[Scriptorium] Make sure git is installed and you have internet access" echo "Make sure git is installed and you have internet access"
exit 1 exit 1
} }
if [ -d "$ASCIIDOC_PLUGIN_DIR" ]; then if [ -d "$ASCIIDOC_PLUGIN_DIR" ]; then
echo "[Scriptorium] Building obsidian-asciidoc plugin..."
cd "$ASCIIDOC_PLUGIN_DIR" cd "$ASCIIDOC_PLUGIN_DIR"
if [ -f "package.json" ]; then if [ -f "package.json" ]; then
npm install && npm run build || { npm install --silent > /dev/null 2>&1 && npm run build --silent > /dev/null 2>&1 || {
echo "[Scriptorium] Error: Could not build obsidian-asciidoc plugin" echo "Error: Could not build obsidian-asciidoc plugin"
echo "[Scriptorium] Check the error messages above"
exit 1 exit 1
} }
else
echo "[Scriptorium] Warning: No package.json found in obsidian-asciidoc plugin"
fi fi
cd "$SCRIPT_DIR" cd "$SCRIPT_DIR"
# Verify installation
if [ -f "${ASCIIDOC_PLUGIN_DIR}/main.js" ] && [ -f "${ASCIIDOC_PLUGIN_DIR}/manifest.json" ]; then if [ -f "${ASCIIDOC_PLUGIN_DIR}/main.js" ] && [ -f "${ASCIIDOC_PLUGIN_DIR}/manifest.json" ]; then
echo "[Scriptorium] obsidian-asciidoc plugin installed successfully!"
# Get plugin ID from manifest.json
ASCIIDOC_PLUGIN_ID=$(node -e "const m=require('${ASCIIDOC_PLUGIN_DIR}/manifest.json'); console.log(m.id)" 2>/dev/null || echo "obsidian-asciidoc") ASCIIDOC_PLUGIN_ID=$(node -e "const m=require('${ASCIIDOC_PLUGIN_DIR}/manifest.json'); console.log(m.id)" 2>/dev/null || echo "obsidian-asciidoc")
enable_plugin "$ASCIIDOC_PLUGIN_ID" > /dev/null 2>&1
# Enable the plugin echo "✓ obsidian-asciidoc plugin installed"
echo "[Scriptorium] Enabling obsidian-asciidoc plugin..."
enable_plugin "$ASCIIDOC_PLUGIN_ID"
else else
echo "[Scriptorium] Error: Plugin files not found after installation" echo "Error: Plugin files not found after installation"
echo "[Scriptorium] main.js or manifest.json missing in ${ASCIIDOC_PLUGIN_DIR}"
exit 1 exit 1
fi fi
fi fi
else else
echo "[Scriptorium] Error: git is not installed. Cannot install obsidian-asciidoc plugin" echo "Error: git is required to install obsidian-asciidoc plugin"
echo "[Scriptorium] Please install git or install the plugin manually"
exit 1 exit 1
fi fi
fi fi
# Start Obsidian # Start Obsidian
echo "[Scriptorium] Starting Obsidian..." echo ""
echo "[Scriptorium] Note: Plugin logs will appear in this terminal" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Starting Obsidian..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Try to find Obsidian command # Try to find Obsidian command
if command -v obsidian &> /dev/null; then if command -v obsidian &> /dev/null; then
# Start Obsidian with the vault path
obsidian "$VAULT_PATH" & obsidian "$VAULT_PATH" &
echo "[Scriptorium] Obsidian started in background (PID: $!)" echo "Obsidian started (PID: $!)"
echo "[Scriptorium] You can close this terminal, but plugin logs will stop if you do" echo "Plugin logs will appear in this terminal"
echo "[Scriptorium] Press Ctrl+C to stop Obsidian (or close the window)" echo "Press Ctrl+C to stop"
echo ""
echo "[Scriptorium] To use a different vault next time, run: $0 <new-vault-path>"
# Wait for user interrupt
wait wait
elif command -v flatpak &> /dev/null && flatpak list | grep -q "md.obsidian"; then elif command -v flatpak &> /dev/null && flatpak list | grep -q "md.obsidian"; then
# Try Flatpak version
echo "[Scriptorium] Starting Obsidian via Flatpak..."
flatpak run md.obsidian.Obsidian "$VAULT_PATH" & flatpak run md.obsidian.Obsidian "$VAULT_PATH" &
echo "[Scriptorium] Obsidian started in background (PID: $!)" echo "Obsidian started via Flatpak (PID: $!)"
echo "[Scriptorium] You can close this terminal, but plugin logs will stop if you do" echo "Plugin logs will appear in this terminal"
echo "[Scriptorium] Press Ctrl+C to stop Obsidian (or close the window)" echo "Press Ctrl+C to stop"
echo ""
echo "[Scriptorium] To use a different vault next time, run: $0 <new-vault-path>"
# Wait for user interrupt
wait wait
else else
echo "Error: Could not find Obsidian command" echo "Error: Could not find Obsidian"
echo "Please install Obsidian or add it to your PATH" echo "Please install Obsidian or start manually:"
echo "Or start Obsidian manually and open vault: $VAULT_PATH" echo " obsidian \"$VAULT_PATH\""
exit 1 exit 1
fi fi

Loading…
Cancel
Save