Automatizace pinů Pinterest pro statické weby pomocí RSS a metaznaček
Pro integraci webu s Pinterest začněte ověřením domény. V Pinterest Business Hub zvolte metodu metaznačky a vložte ji do <head> hlavní stránky:
<meta name="p:domain_verify" content="12ac6ff1eaa70a3386sg439fda58bbb6"/>
To umožní Pinterestu indexovat stránky s Rich Pins. Dále přidejte ke každému článku metaznačky do <head>:
<meta name="is_article" content="true">
<meta name="pinterest_description" content="Popis pro pin, 150–200 znaků">
<meta name="pinterest_image" content="https://example.com/image.webp">
<meta name="article_published_at" content="2026-04-03T12:00:00+03:00">
Obrázek musí být vertikální (1000×1500 px), přes HTTPS, do 2 MB. Bez pinterest_image Pinterest použije první <img> na stránce, často neoptimální.
Generování RSS feedu skriptem Node.js
Pinterest parsuje RSS pro automatické vytváření pinů. Použijte skript pro prohledávání HTML souborů, extrakci metadat a generování rss.xml.
Vytvořte generate-rss.js ve složce scripts:
import fs from 'node:fs/promises';
import path from 'node:path';
import * as cheerio from 'cheerio';
// ================== NASTAVENÍ (UPRAVTE VLASTNÍ) ==================
const BASE_URL = 'https://VÁŠ_WEB.cz';
const ROOT_DIR = path.resolve(process.cwd(), 'dist');
const OUTPUT_RSS_PATH = path.join(ROOT_DIR, 'rss.xml');
const CHANNEL_TITLE = 'Název vašeho blogu';
const CHANNEL_DESCRIPTION = 'Popis: články o vývoji, SEO, designu';
// ================== DÁLE KOD NEMĚNTE ==================
function escapeXml(value = '') {
return value
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function getMimeTypeByExt(urlOrPath = '') {
const ext = urlOrPath.split('.').pop()?.toLowerCase();
switch (ext) {
case 'jpg': case 'jpeg': return 'image/jpeg';
case 'png': return 'image/png';
case 'webp': return 'image/webp';
case 'gif': return 'image/gif';
default: return 'image/*';
}
}
function buildArticleUrl(filePath) {
const relativePath = path.relative(ROOT_DIR, filePath).replace(/\\/g, '/');
return `${BASE_URL}/${relativePath}`;
}
function buildImageUrl(src) {
if (!src) return '';
if (/^https?:\/\//i.test(src)) return src;
if (src.startsWith('/')) return `${BASE_URL}${src}`;
return `${BASE_URL}/${src}`;
}
async function collectHtmlFiles(dir) {
const entries = await fs.readdir(dir, { withFileTypes: true });
const files = [];
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
const nested = await collectHtmlFiles(fullPath);
files.push(...nested);
} else if (entry.isFile() && entry.name.endsWith('.html')) {
files.push(fullPath);
}
}
return files;
}
async function parseArticle(filePath) {
const content = await fs.readFile(filePath, 'utf8');
const $ = cheerio.load(content);
const isArticle = $('meta[name="is_article"]').length > 0;
if (!isArticle) return null;
const title = $('h1').first().text().trim() || 'Bez nadpisu';
const pinterestDescription = $('meta[name="pinterest_description"]').attr('content')?.trim() || '';
const pinterestImg = $('meta[name="pinterest_image"]').attr('content');
let firstImgSrc = $('img').first().attr('src') || '';
if (firstImgSrc.endsWith('.svg')) firstImgSrc = '';
const imageUrl = buildImageUrl(pinterestImg || firstImgSrc);
let pubDate;
const articleDateMeta = $('meta[name="article_published_at"]').attr('content');
if (articleDateMeta) {
const parsed = new Date(articleDateMeta);
if (!isNaN(parsed.getTime())) pubDate = parsed;
}
if (!pubDate) {
const stat = await fs.stat(filePath);
pubDate = stat.mtime;
}
return { title, pinterestDescription, url: buildArticleUrl(filePath), imageUrl, pubDate };
}
function buildRssXml(items) {
const itemsXml = items.map(item => {
const enclosure = item.imageUrl ? `\n <enclosure url="${escapeXml(item.imageUrl)}" type="${getMimeTypeByExt(item.imageUrl)}" />` : '';
return `\n <item>\n <title>${escapeXml(item.title)}</title>\n <link>${escapeXml(item.url)}</link>\n <description><![CDATA[${item.pinterestDescription}]]></description>\n <pubDate>${item.pubDate.toUTCString()}</pubDate>${enclosure}\n </item>`;
}).join('\n');
return `<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0">\n<channel>\n <title>${escapeXml(CHANNEL_TITLE)}</title>\n <link>${escapeXml(BASE_URL)}</link>\n <description>${escapeXml(CHANNEL_DESCRIPTION)}</description>${itemsXml}\n</channel>\n</rss>`;
}
async function main() {
console.log('🔍 Hledání HTML v:', ROOT_DIR);
const htmlFiles = await collectHtmlFiles(ROOT_DIR);
console.log(`📄 Nalezeno HTML: ${htmlFiles.length}`);
const articles = [];
for (const filePath of htmlFiles) {
const article = await parseArticle(filePath);
if (article) articles.push(article);
}
console.log(`📰 Článků s is_article: ${articles.length}`);
if (!articles.length) {
console.warn('⚠️ Žádné články. RSS nevytvořen.');
return;
}
articles.sort((a, b) => b.pubDate - a.pubDate);
const rssXml = buildRssXml(articles);
await fs.writeFile(OUTPUT_RSS_PATH, rssXml, 'utf8');
console.log(`✅ RSS uložen: ${OUTPUT_RSS_PATH}`);
}
main().catch(err => {
console.error('❌ Chyba:', err);
process.exit(1);
});
Spuštění:
npm install cheerio- Nastavte
BASE_URL,ROOT_DIR, kanál. node generate-rss.js
Skript rekurzivně prohledává HTML, parsuje Cheerio, escapuje XML, určuje MIME podle přípony, vytváří absolutní URL. Řadí podle pubDate.
Připojení RSS k Pinterestu a automatizace
V Pinterest: „Vytvořit“ → „Rich Pins“ → „RSS feed“ → vložte https://váš-web.cz/rss.xml. Piny se generují za 6–24 hodin.
Proces:
- Přidejte článek s metaznačkami.
node generate-rss.js.- Pinterest parsuje RSS, vytváří piny z
<title>,<description>,<enclosure>.
Pro plnou automatizaci integrujte do CI/CD (GitHub Actions) nebo cron: 0 0 * cd /cesta/k/projektu && node scripts/generate-rss.js.
Výhody přístupu:
- Funguje se statickými weby (Hugo, Eleventy, čisté HTML).
- Nevyžaduje CMS nebo pluginy.
- Škáluje na tisíce článků.
- Pinterest ukládá RSS do mezipaměti, aktualizace v reálném čase nejsou potřeba.
Co je důležité
- Ověřte doménu metaznačkou
p:domain_verifypro indexaci. - Použijte
pinterest_imagepro kontrolu vizuálu pinů. - Skript zpracovává fallback na
mtimesouboru a první<img>. - RSS obsahuje
<enclosure>pro obrázky s MIME typy. - Automatizujte přes cron nebo CI pro produkci.
— Editorial Team
Zatím žádné komentáře.