Branchwell

PulseCanvas / website / scripts / seo.mjs

1import { websiteUrl, seoPages, socialImage, testflightUrl, sourceUrl } from '../seo.config.js';
2import { films, filmUrl } from '../media.config.js';
3const absolute = (path) => new URL(path, websiteUrl).href;
4const organization = {
5 '@type': 'Organization', '@id': absolute('/#org'), name: 'PulseCanvas', url: absolute('/'),
6 logo: absolute('/images/app-icon.webp'),
7};
8const app = {
9 '@type': 'SoftwareApplication', '@id': absolute('/#app'), name: 'PulseCanvas Studio', url: absolute('/'),
10 description: 'PulseCanvas Studio is a free music visualizer and video maker for Mac, iPhone and iPad. Import a soundtrack, arrange beat-aligned visuals, and export an MP4 with audio, up to 4K at 60 fps.',
11 applicationCategory: 'MultimediaApplication', applicationSubCategory: 'Music visualizer',
12 operatingSystem: 'macOS 14 or later, iOS 18 or later, iPadOS 18 or later, visionOS', processorRequirements: 'Apple silicon (Mac)',
13 isAccessibleForFree: true, offers: { '@type': 'Offer', price: 0, priceCurrency: 'USD' },
14 downloadUrl: [testflightUrl, absolute('/download/')],
15 author: { '@id': organization['@id'] }, publisher: { '@id': organization['@id'] }, sameAs: [testflightUrl],
16 image: absolute('/images/app-icon.png'), screenshot: absolute('/images/app-studio.webp'),
17 featureList: ['Native Metal visualizers in both editions; additional projectM / MilkDrop community effects in Creators Edition', 'Soundtrack import, scrubbing and loop preview', 'Beat-aligned Studio sequences with individual bar lengths', 'Per-visualizer saved styles', 'Save and reopen projects', 'H.264 MP4 exports with audio, up to 4K and 60 fps', 'Wide, landscape, portrait, phone and square canvases'],
18};
19const video = {
20 '@type': 'VideoObject', '@id': absolute('/watch/walkthrough/#video'), name: 'PulseCanvas Studio tutorial: make your first music video',
21 description: seoPages['/watch/walkthrough/'].description, thumbnailUrl: [absolute('/images/tutorial-v6-poster.webp')],
22 // Date first published on this website, rather than the capture's filesystem timestamp.
23 uploadDate: '2026-10-15T22:00:00Z', duration: 'PT1M17.783S', contentUrl: filmUrl(films.walkthrough),
24 url: absolute('/watch/walkthrough/'), inLanguage: 'en', publisher: { '@id': organization['@id'] }, about: { '@id': app['@id'] },
25};
26// Questions and answers as the support and compare pages show them, so the FAQ data can't drift from the visible text.
27const plainText = (markup) => markup.replace(/<[^>]+>/g, '').replace(/&amp;/g, '&').replace(/\s+/g, ' ').trim();
28export function supportFaq(html) {
29 const block = html.match(/<div class="support-faq">([\s\S]*?)<\/div>/)?.[1] || '';
30 return Array.from(block.matchAll(/<h3>([\s\S]*?)<\/h3>\s*<p>([\s\S]*?)<\/p>/g), ([, question, answer]) => ({ question: plainText(question), answer: plainText(answer) }));
31}
32export function structuredData(path, html = '') {
33 const page = seoPages[path];
34 const graph = [organization, { '@type': 'WebSite', '@id': absolute('/#website'), url: absolute('/'), name: 'PulseCanvas Studio', publisher: { '@id': organization['@id'] }, inLanguage: 'en' }, {
35 '@type': page.video ? 'ItemPage' : path.startsWith('/guides/') && path !== '/guides/' ? 'TechArticle' : 'WebPage',
36 '@id': absolute(path + '#page'), url: absolute(path), name: page.title, description: page.description,
37 isPartOf: { '@id': absolute('/#website') }, inLanguage: 'en', publisher: { '@id': organization['@id'] },
38 primaryImageOfPage: { '@type': 'ImageObject', url: absolute(socialImage.path), width: socialImage.width, height: socialImage.height },
39 ...(path.startsWith('/guides/') && path !== '/guides/' ? { headline: page.title, image: absolute('/images/app-studio.webp'), author: { '@id': organization['@id'] } } : {}),
40 ...(page.video ? { mainEntity: { '@id': video['@id'] } } : { about: { '@id': app['@id'] } }),
41 }];
42 graph.push(app);
43 if (page.video) graph.push(video);
44 const faq = ['/help/', '/compare/'].includes(path) ? supportFaq(html) : [];
45 if (faq.length) graph.push({ '@type': 'FAQPage', '@id': absolute(path + '#faq'), url: absolute(path), about: { '@id': app['@id'] }, mainEntity: faq.map(({ question, answer }) => ({ '@type': 'Question', name: question, acceptedAnswer: { '@type': 'Answer', text: answer } })) });
46 if (path !== '/') {
47 const crumbs = [{ name: 'Home', path: '/' }];
48 if (path.startsWith('/guides/') && path !== '/guides/') crumbs.push({ name: 'Guides', path: '/guides/' });
49 crumbs.push({ name: page.name, path });
50 graph.push({ '@type': 'BreadcrumbList', itemListElement: crumbs.map((crumb, i) => ({ '@type': 'ListItem', position: i + 1, name: crumb.name, item: absolute(crumb.path) })) });
51 }
52 return { '@context': 'https://schema.org', '@graph': graph };
53}
54export const sitemap = `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${Object.keys(seoPages).map(path => ` <url><loc>${absolute(path)}</loc></url>`).join('\n')}\n</urlset>\n`;
55// Search engines and AI search, assistant and training crawlers are welcome, and named so the policy is explicit. This does not promise inclusion.
56const aiCrawlers = ['OAI-SearchBot', 'ChatGPT-User', 'GPTBot', 'ClaudeBot', 'Claude-SearchBot', 'Claude-User', 'PerplexityBot', 'Perplexity-User', 'Google-Extended', 'GoogleOther', 'Applebot', 'Applebot-Extended', 'bingbot', 'Amazonbot', 'meta-externalagent', 'meta-externalfetcher', 'DuckAssistBot', 'MistralAI-User', 'CCBot', 'cohere-ai', 'YouBot'];
57export const robots = `# PulseCanvas Studio welcomes search engines and AI assistants.\n# A plain-text summary for language models: ${absolute('/llms.txt')}\n\nUser-agent: *\nAllow: /\n\n# AI search, assistant and training crawlers, allowed by name.\n${aiCrawlers.map(name => `User-agent: ${name}\n`).join('')}Allow: /\n\nSitemap: ${absolute('/sitemap.xml')}\n`;
58// llms.txt: a plain-text summary of the app and a map of the site for AI assistants. Keep it in step with the pages.
59export const llms = `# PulseCanvas Studio
60
61> PulseCanvas Studio is a free music visualizer and video maker for Mac, iPhone and iPad. Import a soundtrack, choose and style visuals, arrange beat-aligned scenes to your song, and export an MP4 with audio, up to 4K at 60 fps.
62
63Key facts:
64
65- Price: free. Creators Edition and the iPhone and iPad beta are free, and every video and export is free. No account or subscription is required.
66- License: the application source is in the public domain (Unlicense).
67- Mac: an Apple silicon Mac with macOS 14 or later. Creators Edition, downloaded from ${absolute('/download/')}, includes over 100 native Metal visualizers plus 7,000+ MilkDrop community effects powered by projectM.
68- iPhone, iPad and Apple Vision Pro: a free beta on TestFlight, on iOS 18 and iPadOS 18 or later and on visionOS. ${testflightUrl}
69- Studio: build a sequence that moves with your music. Studio creates beat-aligned sections automatically, and you choose the visuals and how many bars each scene gets.
70- Export: H.264 MP4 with audio, up to 4K and 60 fps, on wide, landscape, portrait, phone and square canvases.
71- Also included: soundtrack import with scrubbing and loop preview, saved visual styles, projects you can save and reopen, and Radio.
72- Community effects: Creators Edition draws its 7,000+ effects from Cream of the Crop, a curated MilkDrop collection by ISOSCELES.
73
74## Pages
75
76${Object.entries(seoPages).filter(([path]) => !['/privacy/', '/licenses/'].includes(path)).map(([path, page]) => `- [${path === '/' ? 'PulseCanvas Studio' : page.name}](${absolute(path)}): ${page.description}`).join('\n')}
77
78## Optional
79
80- [Privacy Policy](${absolute('/privacy/')})
81- [Licenses](${absolute('/licenses/')})
82`;
83export function seoPlugin() {
84 return {
85 name: 'pulsecanvas-seo',
86 transformIndexHtml: {
87 order: 'pre',
88 handler(html, context) {
89 const path = context.path.replace(/index\.html$/, '').replace(/\/{2,}/g, '/');
90 if (path === "/404.html") return html;
91 const page = seoPages[path];
92 if (!page) throw new Error(`Missing SEO configuration for ${context.path}`);
93 // Replace legacy metadata, so every route has exactly one canonical title and description.
94 html = html.replace('href="/images/app-icon.png"', 'href="/images/favicon.png"')
95 .replace(/<title>[\s\S]*?<\/title>/gi, '')
96 .replace(/<meta\b(?=[^>]*\b(?:name\s*=\s*["'](?:description|robots|msvalidate\.01|twitter:[^"']+)["']|property\s*=\s*["']og:[^"']+["']))[^>]*>/gi, '')
97 .replace(/<link\b(?=[^>]*\brel\s*=\s*["']canonical["'])[^>]*>/gi, '')
98 .replace(/<script\b(?=[^>]*\btype\s*=\s*["']application\/ld\+json["'])[^>]*>[\s\S]*?<\/script>/gi, '');
99 return { html, tags: [
100 { tag: 'title', children: page.title },
101 { tag: 'meta', attrs: { name: 'description', content: page.description } },
102 ...(path === '/' ? [{ tag: 'meta', attrs: { name: 'msvalidate.01', content: 'E2001B47E91F72A19BB1E8E642B26928' } }] : []),
103 { tag: 'link', attrs: { rel: 'canonical', href: absolute(path) } },
104 { tag: 'meta', attrs: { name: 'robots', content: 'index, follow, max-image-preview:large, max-video-preview:-1' } },
105 ...Object.entries({
106 'og:title': page.socialTitle || page.title, 'og:description': page.description,
107 'og:type': path.startsWith('/guides/') && path !== '/guides/' ? 'article' : 'website',
108 'og:url': absolute(path), 'og:site_name': 'PulseCanvas Studio', 'og:locale': 'en_US',
109 'og:image': absolute(socialImage.path), 'og:image:secure_url': absolute(socialImage.path),
110 'og:image:type': socialImage.type, 'og:image:width': String(socialImage.width),
111 'og:image:height': String(socialImage.height), 'og:image:alt': socialImage.alt,
112 }).map(([property, content]) => ({ tag: 'meta', attrs: { property, content } })),
113 ...Object.entries({
114 'twitter:card': 'summary_large_image', 'twitter:title': page.socialTitle || page.title,
115 'twitter:description': page.description, 'twitter:image': absolute(socialImage.path),
116 'twitter:image:alt': socialImage.alt,
117 }).map(([name, content]) => ({ tag: 'meta', attrs: { name, content } })),
118 { tag: 'script', attrs: { type: 'application/ld+json' }, children: JSON.stringify(structuredData(path, html)).replaceAll('<', '\\u003c') },
119 ].map(tag => ({ ...tag, injectTo: 'head' })) };
120 },
121 },
122 configureServer(server) {
123 server.middlewares.use((request, response, next) => {
124 const route = request.url?.split('?')[0];
125 if (!['/sitemap.xml', '/robots.txt', '/llms.txt'].includes(route)) return next();
126 response.setHeader('Content-Type', route.endsWith('.xml') ? 'application/xml' : 'text/plain');
127 response.end(route === '/sitemap.xml' ? sitemap : route === '/llms.txt' ? llms : robots);
128 });
129 },
130 generateBundle() {
131 this.emitFile({ type: 'asset', fileName: 'sitemap.xml', source: sitemap });
132 this.emitFile({ type: 'asset', fileName: 'robots.txt', source: robots });
133 this.emitFile({ type: 'asset', fileName: 'llms.txt', source: llms });
134 },
135 };
136}