Scripts de automação

Linux/macOS — scripts/update-vault.sh

#!/bin/bash
 
set -euo pipefail
 
echo "🚀 Atualizando vault de conhecimento..."
 
echo "📋 Copiando configuração..."
cp vault.config.ts obsidian-site/quartz.config.ts
 
echo "🔨 Gerando site estático..."
cd obsidian-site
npx quartz build
cd ..
 
echo "📦 Copiando arquivos..."
rm -rf public/vault/*
mkdir -p public/vault
cp -r obsidian-site/public/* public/vault/
 
echo "🔧 Corrigindo links..."
node scripts/fix-links.js
 
echo "✅ Pronto! Acesse http://localhost:3000/vault"

Tornar executável:

chmod +x scripts/update-vault.sh

Windows — scripts/update-vault.ps1

Write-Host "🚀 Atualizando vault de conhecimento..." -ForegroundColor Green
 
Write-Host "📋 Copiando configuração..." -ForegroundColor Cyan
Copy-Item vault.config.ts obsidian-site/quartz.config.ts -Force
 
Write-Host "🔨 Gerando site estático..." -ForegroundColor Cyan
Set-Location obsidian-site
npx quartz build
Set-Location ..
 
Write-Host "📦 Copiando arquivos..." -ForegroundColor Cyan
if (Test-Path public/vault) { Remove-Item -Path public/vault/* -Recurse -Force }
New-Item -Path public/vault -ItemType Directory -Force | Out-Null
Copy-Item -Path obsidian-site/public/* -Destination public/vault/ -Recurse -Force
 
Write-Host "🔧 Corrigindo links..." -ForegroundColor Cyan
node scripts/fix-links.js
 
Write-Host "✅ Pronto! Acesse http://localhost:3000/vault" -ForegroundColor Green
const fs = require('fs');
const path = require('path');
 
const VAULT_DIR = path.join(__dirname, '../public/vault');
 
function fixHtmlLinks(dir) {
  const files = fs.readdirSync(dir);
 
  files.forEach(file => {
    const filePath = path.join(dir, file);
    const stat = fs.statSync(filePath);
 
    if (stat.isDirectory()) {
      fixHtmlLinks(filePath);
    } else if (file.endsWith('.html')) {
      let content = fs.readFileSync(filePath, 'utf8');
 
      content = content.replace(
        /href="(\/vault\/[^"#?]*?)(?<!\.html)(\?[^"]*)?("#[^"]*)?"/g,
        (match, url, query, hash) => {
          return `href="${url}.html${query || ''}${hash || ''}"`;
        }
      );
 
      fs.writeFileSync(filePath, content);
    }
  });
}
 
function fixContentIndex() {
  const indexPath = path.join(VAULT_DIR, 'static/contentIndex.json');
 
  if (fs.existsSync(indexPath)) {
    let index = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
 
    for (const key of Object.keys(index)) {
      if (!key.endsWith('.html') && !key.includes('.')) {
        const newKey = `${key}.html`;
        index[newKey] = index[key];
        delete index[key];
      }
    }
 
    fs.writeFileSync(indexPath, JSON.stringify(index, null, 2));
  }
}
 
console.log('🔧 Corrigindo links HTML...');
fixHtmlLinks(VAULT_DIR);
 
console.log('📝 Corrigindo índice de conteúdo...');
fixContentIndex();
 
console.log('✅ Links corrigidos!');