Skip to content

Commit

Permalink
Index Now Fix
Browse files Browse the repository at this point in the history
A la tercera va la vencida?
  • Loading branch information
TeenBiscuits committed Nov 16, 2024
1 parent 4b6e134 commit ab928c0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pnpm-debug.log*
# environment variables
.env
.env.production
.env*.local

# index now key
public/*.txt
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"prebuild": "node -e \"require('dotenv').config(); const fs = require('fs'); const path = require('path'); const fileName = (process.env.FILE_NAME && process.env.FILE_NAME.trim() !== '') ? process.env.FILE_NAME : 'indexnow'; const filePath = path.join(__dirname, 'public', `${fileName}.txt`); console.log('FILE_NAME:', fileName, 'filePath:', filePath); fs.mkdirSync(path.dirname(filePath), { recursive: true }); if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) { throw new Error('La ruta especificada apunta a un directorio, no a un archivo. Verifica FILE_NAME.'); } fs.writeFileSync(filePath, fileName);\"",
"prebuild": "node scripts/indexnow.js",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
Expand Down
16 changes: 16 additions & 0 deletions scripts/indexnow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import dotenv from 'dotenv';
import { writeFileSync } from 'fs';
import { join } from 'path';

dotenv.config();
const myEnvVar = process.env.INDEXNOW_KEY;

if (myEnvVar) {
const filePath = join('./public', `${myEnvVar}.txt`);
const fileContent = `${myEnvVar}`;
writeFileSync(filePath, fileContent, 'utf-8');
console.log('Archivo creado correctamente en ./public');
} else {
console.error('La variable de entorno no está definida');
process.exit(1);
}

0 comments on commit ab928c0

Please sign in to comment.