Skip to content

Commit

Permalink
generate robots.txt dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Dec 20, 2024
1 parent ce28aa5 commit cb8e3ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 0 additions & 2 deletions public/robots.txt

This file was deleted.

14 changes: 14 additions & 0 deletions src/app/robots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getGitInfo } from "@/utils/git-info";
import { MetadataRoute } from "next";

export default async function robots(): Promise<MetadataRoute.Robots> {
const gitInfo = await getGitInfo()
const isDevWebsite = gitInfo?.isDev ?? false

return {
rules: {
userAgent: '*',
[isDevWebsite ? 'disallow' : 'allow']: '/',
},
}
}
2 changes: 1 addition & 1 deletion src/utils/git-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function tryGetGitInfoFromCommand(): Promise<GitInfo | undefined> {
if (branch && commitHash) {
return {
branch, commitHash,
isDev: false, // treat local development environment as isDev=false
isDev: false, // treat local development environment as the prod website
}
}
} catch {
Expand Down

0 comments on commit cb8e3ad

Please sign in to comment.