diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index eb05362..0000000 --- a/public/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -User-agent: * -Disallow: diff --git a/src/app/robots.ts b/src/app/robots.ts new file mode 100644 index 0000000..e58891d --- /dev/null +++ b/src/app/robots.ts @@ -0,0 +1,14 @@ +import { getGitInfo } from "@/utils/git-info"; +import { MetadataRoute } from "next"; + +export default async function robots(): Promise { + const gitInfo = await getGitInfo() + const isDevWebsite = gitInfo?.isDev ?? false + + return { + rules: { + userAgent: '*', + [isDevWebsite ? 'disallow' : 'allow']: '/', + }, + } +} diff --git a/src/utils/git-info.ts b/src/utils/git-info.ts index e9d1325..c978788 100644 --- a/src/utils/git-info.ts +++ b/src/utils/git-info.ts @@ -33,7 +33,7 @@ async function tryGetGitInfoFromCommand(): Promise { 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 {