Zurück zur Startseite

Pinterest Auto-Pins-Setup für Website

Anleitung zum Einrichten automatischer Pinterest-Pins für statische Websites. Domain-Verifizierung, Artikel-Meta-Tags, Node.js-Skript für RSS-Generierung aus HTML. Verbindung zu Pinterest Business für Traffic.

Pinterest Auto Pins: RSS-Generator mit Node.js
Advertisement 728x90

Automatisierung von Pinterest-Pins für statische Websites via RSS und Meta-Tags

Um Ihre Website mit Pinterest zu integrieren, beginnen Sie mit der Domain-Verifizierung. Im Pinterest Business Hub wählen Sie die Meta-Tag-Methode und fügen sie in den <head> Ihrer Startseite ein:

<meta name="p:domain_verify" content="12ac6ff1eaa70a3386sg439fda58bbb6"/>

Dies ermöglicht Pinterest, Seiten mit Rich Pins zu indexieren. Fügen Sie anschließend Meta-Tags zum <head> jedes Artikels hinzu:

<meta name="is_article" content="true">
<meta name="pinterest_description" content="Pin-Beschreibung, 150–200 Zeichen">
<meta name="pinterest_image" content="https://example.com/image.webp">
<meta name="article_published_at" content="2026-04-03T12:00:00+03:00">

Das Bild sollte vertikal sein (1000×1500 px), über HTTPS bereitgestellt werden und unter 2 MB liegen. Ohne pinterest_image verwendet Pinterest das erste <img> auf der Seite, was oft suboptimal ist.

Google AdInline article slot

Generierung eines RSS-Feeds mit einem Node.js-Skript

Pinterest analysiert RSS, um automatisch Pins zu erstellen. Verwenden Sie ein Skript, um HTML-Dateien zu scannen, Metadaten zu extrahieren und rss.xml zu generieren.

Erstellen Sie generate-rss.js in einem scripts-Ordner:

import fs from 'node:fs/promises';
import path from 'node:path';
import * as cheerio from 'cheerio';

// ================== EINSTELLUNGEN (HIER ANPASSEN) ==================

const BASE_URL = 'https://IHRE_SEITE.com';
const ROOT_DIR = path.resolve(process.cwd(), 'dist');
const OUTPUT_RSS_PATH = path.join(ROOT_DIR, 'rss.xml');
const CHANNEL_TITLE = 'Ihr Blog-Name';
const CHANNEL_DESCRIPTION = 'Beschreibung: Artikel zu Entwicklung, SEO, Design';

// ================== NICHT UNTER DIESER LINIE ÄNDERN ==================

function escapeXml(value = '') {
  return value
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;');
}

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() || 'Kein Titel';
  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('🔍 Suche HTML in:', ROOT_DIR);
  const htmlFiles = await collectHtmlFiles(ROOT_DIR);
  console.log(`📄 HTML-Dateien gefunden: ${htmlFiles.length}`);

  const articles = [];
  for (const filePath of htmlFiles) {
    const article = await parseArticle(filePath);
    if (article) articles.push(article);
  }
  console.log(`📰 Artikel mit is_article: ${articles.length}`);

  if (!articles.length) {
    console.warn('⚠️ Keine Artikel gefunden. RSS nicht erstellt.');
    return;
  }

  articles.sort((a, b) => b.pubDate - a.pubDate);
  const rssXml = buildRssXml(articles);
  await fs.writeFile(OUTPUT_RSS_PATH, rssXml, 'utf8');
  console.log(`✅ RSS gespeichert: ${OUTPUT_RSS_PATH}`);
}

main().catch(err => {
  console.error('❌ Fehler:', err);
  process.exit(1);
});

Ausführung:

Google AdInline article slot
  • npm install cheerio
  • Konfigurieren Sie BASE_URL, ROOT_DIR und Kanal-Details.
  • node generate-rss.js

Das Skript scannt HTML rekursiv, parst mit Cheerio, maskiert XML, bestimmt MIME-Typen nach Erweiterung und baut absolute URLs. Es sortiert nach pubDate.

Verbindung von RSS zu Pinterest und Automatisierung

In Pinterest: "Erstellen" → "Rich Pins" → "RSS-Feed" → https://ihre-seite.com/rss.xml einfügen. Pins werden innerhalb von 6–24 Stunden generiert.

Prozess:

Google AdInline article slot
  • Artikel mit Meta-Tags hinzufügen.
  • node generate-rss.js ausführen.
  • Pinterest analysiert den RSS und erstellt Pins aus <title>, <description> und <enclosure>.

Für vollständige Automatisierung, integrieren Sie in CI/CD (z.B. GitHub Actions) oder cron: 0 0 * cd /pfad/zum/projekt && node scripts/generate-rss.js.

Vorteile dieses Ansatzes:

  • Funktioniert mit statischen Websites (Hugo, Eleventy, einfaches HTML).
  • Kein CMS oder Plugins erforderlich.
  • Skaliert auf Tausende von Artikeln.
  • Pinterest cached RSS, daher sind Echtzeit-Updates nicht nötig.

Wichtige Punkte

  • Verifizieren Sie Ihre Domain mit dem p:domain_verify Meta-Tag für die Indexierung.
  • Verwenden Sie pinterest_image, um die Pin-Visuals zu steuern.
  • Das Skript behandelt Fallbacks auf Datei-mtime und das erste <img>.
  • RSS enthält <enclosure> für Bilder mit MIME-Typen.
  • Automatisieren Sie via cron oder CI für die Produktion.

— Editorial Team

Advertisement 728x90

Weiterlesen