Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Build a Static Local Directory from a Google Maps CSV

A local business directory looks like a database app: thousands of listings, search, filters, a map and a page per city. In practice almost all of it can be static HTML generated once from a spreadsheet. That makes it fa

A local business directory looks like a database app: thousands of listings, search, filters, a map and a page per city. In practice almost all of it can be static HTML generated once from a spreadsheet. That makes it fast, cheap to host anywhere and very hard to break.

This post walks through the shape of that build, starting from a Google Maps business export.

The input

The starting point is a CSV of businesses, usually pulled with Outscraper, Apify or any scraper that reads Google Maps. A typical row has a name, category, full address, city, county or region, postal code, phone, website, latitude, longitude, rating, review count and opening hours.

Before generating anything, clean it:

  • Drop rows with no address or no coordinates
  • Normalize city names so "St. Albans" and "Saint Albans" become one city
  • Merge near-duplicate categories into the short list you want visitors to see
  • Remove permanently closed businesses if the export marks them
  • Deduplicate by place ID, or by name plus address when there is no ID

A small Python or Node script handles all of this. Keep the cleaning rules in code so the next refresh runs the same way.

The page tree

A directory has a predictable set of pages, and each one is a template plus a slice of the data:

  • A homepage with search, top categories and top regions
  • One page per region listing its cities
  • One page per city listing businesses, grouped or filterable by category
  • Optionally one page per category per city, for niches where people search that way
  • A sitemap and a robots file

Generate slugs once from the cleaned names and keep them stable between refreshes. Changing a URL loses whatever search visibility the old page had built.

Search and filters without a server

Client-side search works well up to tens of thousands of listings. At build time, write a compact JSON index with only the fields search needs: name, category, city, slug and maybe a short keyword string. Load it on demand when the visitor focuses the search box, and filter in the browser.

Filters on a city page are simpler still. Render every listing into the HTML with data attributes for category, rating band and any yes or no fields such as weekend hours. A few lines of JavaScript show and hide cards when a filter changes. No request leaves the page.

The map

A map with a marker per listing is a common request. Use a lightweight library such as Leaflet with an open tile provider, and only load it when the map section scrolls into view. On city pages with hundreds of listings, cluster the markers so the map stays readable on a phone.

Contact forms

A static site can still have a contact form. Point it at a form handler from your host or a small serverless function. Keep the form short and send submissions to one inbox so nothing gets lost.

Deploying

The output is a folder of HTML, CSS, JS and JSON. Any static host will serve it: GitHub Pages, GitLab Pages, Cloudflare Pages, Netlify or Vercel all work, and most handle tens of thousands of files without trouble. Build in CI so a fresh export can go from CSV to live site with one push.

Refreshing the data

Businesses open, close and change hours all the time, so plan for refreshes from the start. Diff the new export against the previous one and log what changed: new listings, removed listings and changed phones or websites. Regenerate the site, check the diff, and deploy.

The static directory tech notes go further into page generation, search indexes and hosting. For the design side, there's a short guide on what belongs above the fold on a directory homepage.

Static is a good default for directories. Most of the work is in the data, and once that's clean, the site itself is a few templates and a build script.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.