generated from 11ty/eleventy-base-blog
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: ".IA Isla Anticitera - Base de Conocimiento" | ||
description: "En este proyecto se contiene el conocimiento relevante para el asistente Anticitera de OpenAI y la información para promover la creación del dominio de nivel superior .IA" | ||
url: "https://anticitera.deft.work" | ||
--- | ||
|
||
# [.IA Isla Anticitera - Base de Conocimiento](https://anticitera.deft.work) | ||
|
||
En este proyecto se contiene el conocimiento relevante para el asistente Anticitera de OpenAI y la información para promover la creación del dominio de nivel superior .IA | ||
|
||
![Imagen](/img/Cabecera.webp) | ||
![Imagen](https://avatars.githubusercontent.com/u/1455507?v=4) | ||
![Imagen](https://github.com/elswork/anticitera.deft.work/assets/1455507/c5bc98b0-142a-4421-9e25-ebd9417a41b2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const fetch = require('node-fetch'); | ||
const cheerio = require('cheerio'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
async function extractMetadataAndImages(url) { | ||
const response = await fetch(url); | ||
const html = await response.text(); | ||
const $ = cheerio.load(html); | ||
|
||
const title = $('meta[property="og:title"]').attr('content') || $('title').text(); | ||
const description = $('meta[property="og:description"]').attr('content') || $('meta[name="description"]').attr('content'); | ||
|
||
// Extraer URLs de imágenes | ||
const imageUrls = []; | ||
$('img').each((i, elem) => { | ||
const src = $(elem).attr('src'); | ||
if (src) { | ||
imageUrls.push(src); | ||
} | ||
}); | ||
|
||
return { title, description, imageUrls }; | ||
} | ||
|
||
async function createMarkdownFile(url, metadata) { | ||
let content = `--- | ||
title: "${metadata.title}" | ||
description: "${metadata.description}" | ||
url: "${url}" | ||
--- | ||
# [${metadata.title}](${url}) | ||
${metadata.description} | ||
`; | ||
|
||
// Añadir imágenes al contenido Markdown | ||
metadata.imageUrls.forEach(imgUrl => { | ||
content += `![Imagen](${imgUrl})\n`; | ||
}); | ||
|
||
const filename = path.basename(url) + '.md'; | ||
const linksDir = path.join(__dirname, 'content', 'links'); | ||
if (!fs.existsSync(linksDir)) { | ||
fs.mkdirSync(linksDir, { recursive: true }); | ||
} | ||
const filePath = path.join(linksDir, filename); | ||
fs.writeFileSync(filePath, content); | ||
} | ||
|
||
// Ejemplo de uso | ||
const url = 'https://anticitera.deft.work'; // La URL del enlace subido | ||
extractMetadataAndImages(url).then(metadata => { | ||
createMarkdownFile(url, metadata); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters