How I Built 130 Local Service Pages With Vanilla JS and GitHub Pages

2026-12-02来源 dev.toEnglish

My repair business, Xigox, serves customers along Mumbai's Western railway line, from Churchgate to Virar: 29 stations and a dozen services. I wanted a simple, fast static site with a page per station and per core service, without a build tool or a CMS.

The result is a GitHub Pages site with 130 pages generated by one small JavaScript function.

The data

Everything lives in two plain objects:

const stations = [ { n: "Churchgate", s: "churchgate", br: ["worli"] }, { n: "Andheri", s: "andheri", br: ["andheriw", "andherie", "parsi"] }, // ...29 stations in line order ]; const copy = { screen: { churchgate: [intro, whatWeSee, localTip], /* ... */ }, battery: { /* ... */ }, body: { /* ... */ }, }; 

The important part is copy. Each station has its own intro, observations and tip for each core service. Swapping only the city name produces "doorway pages", which search engines treat as spam. Station-specific content is what makes each page worth existing.

The generator

A single template function builds every page:

const page = (title, desc, path, body) => `<!DOCTYPE html> <html lang="en"><head> <meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"> <title>${title}</title><meta name="description" content="${desc}"> <link rel="canonical" href="${BASE}${path}"> <style>${CSS}</style></head> <body><main>${body}</main></body></html>`; 

Then three loops: station × core service pages, one hub page per service, and one page per station that links to its services. Each page links to the previous and next station, so crawlers (and people) can walk the whole line.

Sitemap and robots

files["sitemap.xml"] = `<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${ Object.keys(files).filter(f => f.endsWith(".html")) .map(f => `<url><loc>${BASE}${f === "index.html" ? "" : f}</loc></url>`).join("") }</urlset>`; 

Add a robots.txt pointing at it, verify the site in Google Search Console with the HTML file method, and submit the sitemap.

Lessons

  1. Content beats count. Three services with genuinely local text per station beat twelve with copy-paste.
  2. Flat files are fine. laptop-screen-replacement-andheri.html is a perfectly good URL.
  3. No build step needed. For a small business site, a 100-line generator and GitHub Pages are enough.

If you're curious about the actual repair side, the Xigox price list is public.

原文:https://www.a8q9.cn/en/article/how-i-built-130-local-service-pages-with-vanilla-js-and-github-pages-281951.html

相关文章