Skip to content

feat(vite): add IndexNow build plugin#13

Merged
jaysin586 merged 1 commit into
mainfrom
codex/indexnow-vite-plugin
Jun 17, 2026
Merged

feat(vite): add IndexNow build plugin#13
jaysin586 merged 1 commit into
mainfrom
codex/indexnow-vite-plugin

Conversation

@jaysin586

Copy link
Copy Markdown
Contributor

Summary

Adds a shared docs-kit Vite plugin for IndexNow submissions so docs projects can stop carrying their own deploy:indexnow script. The plugin runs only for production Vite builds and skips submission when the local verification key file is missing, which keeps local builds quiet.

Changes

✨ New features

  • Add indexNowPlugin() to submit sitemap-manifest URLs to IndexNow after production builds.
  • Export indexNowPlugin and IndexNowOptions from @humanspeak/docs-kit/vite.

🔧 Safeguards

  • Guard submissions behind apply: 'build' and Vite production mode by default.
  • Skip IndexNow when static/<key>.txt is missing, with keyFilePath: false available for custom verification setups.
  • Deduplicate/sort URLs and share a once-per-process promise to avoid double submits across SvelteKit build passes.

🧪 Testing

  • pnpm check
  • pnpm build
  • pnpm exec prettier --check src/lib/vite/indexnow.ts src/lib/vite/index.ts

Commits

  • 904cc13 feat(vite): add IndexNow build plugin

Add a production-only Vite plugin that submits sitemap manifest URLs
to IndexNow after builds, with a local verification-key guard for
non-deploy environments.
@jaysin586 jaysin586 self-assigned this Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

A new Vite plugin file src/lib/vite/indexnow.ts is added, implementing indexNowPlugin that reads a sitemap manifest after production builds, normalizes and filters URLs, and submits them to an IndexNow endpoint via HTTP POST. It includes concurrency deduplication via globalThis, optional key-file verification, and configurable error handling. The plugin and its IndexNowOptions type are re-exported from the vite package entry point.

Changes

IndexNow Vite Plugin

Layer / File(s) Summary
Options contract, validation, and manifest helpers
src/lib/vite/indexnow.ts
Defines IndexNowOptions interface with all configuration fields, assertOptions for required-field validation, URL/route normalization and deduplication helpers, key-file path resolution, and readManifest for reading and type-checking the sitemap manifest JSON from disk.
Plugin factory, submission flow, lifecycle wiring, and re-export
src/lib/vite/indexnow.ts, src/lib/vite/index.ts
Implements indexNowPlugin using a globalThis-stored Map for per-parameter deduplication of in-flight submissions. The submission function checks key-file existence, filters and normalizes manifest routes and extraUrls, POSTs to the IndexNow endpoint, and either throws or logs warnings based on failOnError. Vite lifecycle hooks (configResolved, closeBundle) gate submission to apply: 'build' and configured production modes. indexNowPlugin and IndexNowOptions are re-exported from the vite entry point.

Sequence Diagram(s)

sequenceDiagram
  participant ViteBuild
  participant indexNowPlugin
  participant FileSystem
  participant IndexNowAPI

  ViteBuild->>indexNowPlugin: configResolved(config)
  indexNowPlugin->>indexNowPlugin: store root, evaluate shouldSubmit
  ViteBuild->>indexNowPlugin: closeBundle()
  alt shouldSubmit is false
    indexNowPlugin-->>ViteBuild: skip
  else shouldSubmit is true
    indexNowPlugin->>indexNowPlugin: check globalThis dedup map for existing promise
    indexNowPlugin->>FileSystem: readFile(sitemap-manifest.json)
    FileSystem-->>indexNowPlugin: manifest JSON
    indexNowPlugin->>FileSystem: access(<key>.txt)
    FileSystem-->>indexNowPlugin: exists or ENOENT
    alt key file missing
      indexNowPlugin-->>ViteBuild: log warning, skip
    else key file present
      indexNowPlugin->>indexNowPlugin: filter by excludePrefixes, normalize + deduplicate URLs
      indexNowPlugin->>IndexNowAPI: POST endpoint (key, host, urlList)
      IndexNowAPI-->>indexNowPlugin: 200 Accepted / error status
      alt failOnError true and error
        indexNowPlugin-->>ViteBuild: throw Error
      else failOnError false
        indexNowPlugin-->>ViteBuild: log warning
      end
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the sitemap's done,
A POST to IndexNow — let search engines run!
The key file checked, the routes all neat,
Deduped and sorted, no URL repeat.
One plugin wired, the build complete! 🌐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(vite): add IndexNow build plugin' clearly and concisely summarizes the main change—adding a new Vite plugin for IndexNow.
Description check ✅ Passed The description thoroughly details the plugin's purpose, features, safeguards, and testing steps, all directly related to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/indexnow-vite-plugin

Comment @coderabbitai help to get the list of available commands and usage tips.

@jaysin586 jaysin586 merged commit 136b988 into main Jun 17, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant