Initial commit

This commit is contained in:
2026-02-02 22:47:52 +03:00
committed by GitHub
commit f53016aeda
239 changed files with 84360 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
/* This is a script to build the site with Pagefind */
const { execSync } = require('child_process');
const { existsSync } = require('fs');
const { join } = require('path');
// Detect the platform
function detectPlatform() {
// Check environment variables
if (process.env.VERCEL) {
return 'vercel';
}
if (process.env.CF_PAGES) {
return 'cloudflare';
}
if (process.env.NETLIFY) {
return 'netlify';
}
if (process.env.GITHUB_ACTIONS) {
return 'github';
}
// Check if specific directories exist
if (existsSync('.vercel')) {
return 'vercel';
}
// Default to standard dist directory
return 'default';
}
// Get Pagefind output directory
function getPagefindOutputDir(platform) {
const outputDirs = {
vercel: '.vercel/output/static',
cloudflare: 'dist',
netlify: 'dist',
github: 'dist',
default: 'dist'
};
return outputDirs[platform] || 'dist';
}
// Main function
function main() {
const platform = detectPlatform();
const outputDir = getPagefindOutputDir(platform);
console.log(`🚀 Detected deployment platform: ${platform}`);
console.log(`📁 Pagefind output directory: ${outputDir}`);
try {
// Run Astro build
console.log('🔨 Running Astro build...');
execSync(`npx astro build`.trim(), {
stdio: 'inherit',
cwd: process.cwd() // Ensure in the correct directory
});
// Check if output directory exists
if (!existsSync(outputDir)) {
console.error(`❌ Output directory does not exist: ${outputDir}`);
process.exit(1);
}
// Run Pagefind
console.log(`🔍 Running Pagefind search index generation...`);
execSync(`npx pagefind --site ${outputDir}`, {
stdio: 'inherit',
cwd: process.cwd() // Ensure in the correct directory
});
console.log('✅ Build completed!');
console.log(`📊 Search index generated at: ${outputDir}/pagefind/`);
} catch (error) {
console.error('❌ Build failed:', error.message);
process.exit(1);
}
}
main();

View File

@@ -0,0 +1,86 @@
/* This is a script to compile inline Stylus */
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Recursively list files under a directory
function walk(dir) {
const res = [];
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const e of entries) {
const full = path.join(dir, e.name);
if (e.isDirectory()) res.push(...walk(full));
else res.push(full);
}
return res;
}
const srcDir = path.resolve('src');
if (!fs.existsSync(srcDir)) {
console.error('No src directory found.');
process.exit(1);
}
const files = walk(srcDir);
const styleBlockRe = /<style[^>]*lang=["']stylus["'][^>]*>([\s\S]*?)<\/style>/ig;
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
const outNull = process.platform === 'win32' ? 'nul' : '/dev/null';
let failed = false;
function compileStylusContent(content, tmpPath) {
fs.writeFileSync(tmpPath, content, 'utf8');
try {
execSync(`${npxCmd} stylus "${tmpPath}" -o ${outNull}`, { stdio: 'pipe' });
fs.unlinkSync(tmpPath);
return { ok: true };
} catch (err) {
const msg = err.stderr ? err.stderr.toString() : err.message;
// keep temp file for debugging
return { ok: false, error: msg };
}
}
// Check .styl files
const stylFiles = files.filter(f => f.endsWith('.styl'));
for (const f of stylFiles) {
const content = fs.readFileSync(f, 'utf8');
const tmp = f + '.tmp.styl';
const r = compileStylusContent(content, tmp);
if (r.ok) console.log(`${f}: OK`);
else {
failed = true;
console.error(`${f}: ERROR\n${r.error}`);
}
}
// Check inline <style lang="stylus"> blocks in component files
const candidateExt = ['.astro', '.svelte', '.vue', '.html'];
for (const f of files) {
if (!candidateExt.includes(path.extname(f))) continue;
const text = fs.readFileSync(f, 'utf8');
let m;
styleBlockRe.lastIndex = 0;
let idx = 0;
while ((m = styleBlockRe.exec(text)) !== null) {
idx += 1;
const content = m[1].trim();
const tmp = `${f}.style.${idx}.tmp.styl`;
const r = compileStylusContent(content, tmp);
if (r.ok) console.log(`${f} [style #${idx}]: OK`);
else {
failed = true;
console.error(`${f} [style #${idx}]: ERROR\n${r.error}`);
}
}
}
if (failed) {
console.error('\nStylus check failed. Fix above errors.');
process.exit(1);
} else {
console.log('\nAll Stylus checks passed.');
process.exit(0);
}

59
scripts/new-post.js Normal file
View File

@@ -0,0 +1,59 @@
/* This is a script to create a new post markdown file with front-matter */
import fs from "fs"
import path from "path"
function getDate() {
const today = new Date()
const year = today.getFullYear()
const month = String(today.getMonth() + 1).padStart(2, "0")
const day = String(today.getDate()).padStart(2, "0")
return `${year}-${month}-${day}`
}
const args = process.argv.slice(2)
if (args.length === 0) {
console.error(`Error: No filename argument provided
Usage: npm run new-post -- <filename>`)
process.exit(1) // Terminate the script and return error code 1
}
let fileName = args[0]
// Add .md extension if not present
const fileExtensionRegex = /\.(md|mdx)$/i
if (!fileExtensionRegex.test(fileName)) {
fileName += ".md"
}
const targetDir = "./src/content/posts/"
const fullPath = path.join(targetDir, fileName)
if (fs.existsSync(fullPath)) {
console.error(`Error: File ${fullPath} already exists `)
process.exit(1)
}
// recursive mode creates multi-level directories
const dirPath = path.dirname(fullPath)
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true })
}
const content = `---
title: ${args[0]}
published: ${getDate()}
description: ''
image: ''
tags: []
category: ''
draft: false
lang: ''
---
`
fs.writeFileSync(path.join(targetDir, fileName), content)
console.log(`Post ${fullPath} created`)