-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Meier Lukas <[email protected]>
- Loading branch information
1 parent
d20384d
commit 19cd41a
Showing
11 changed files
with
227 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/nextjs/src/app/[locale]/manage/settings/_components/crawling-and-indexing.settings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { Card, LoadingOverlay, Stack, Text, Title } from "@mantine/core"; | ||
|
||
import { clientApi } from "@homarr/api/client"; | ||
import { useForm } from "@homarr/form"; | ||
import type { defaultServerSettings } from "@homarr/server-settings"; | ||
import { useScopedI18n } from "@homarr/translation/client"; | ||
|
||
import { SwitchSetting } from "~/app/[locale]/manage/settings/_components/setting-switch"; | ||
import { revalidatePathActionAsync } from "~/app/revalidatePathAction"; | ||
|
||
interface CrawlingAndIndexingSettingsProps { | ||
initialData: typeof defaultServerSettings.crawlingAndIndexing; | ||
} | ||
|
||
export const CrawlingAndIndexingSettings = ({ initialData }: CrawlingAndIndexingSettingsProps) => { | ||
const t = useScopedI18n("management.page.settings.section.crawlingAndIndexing"); | ||
const form = useForm({ | ||
initialValues: initialData, | ||
onValuesChange: (updatedValues, _) => { | ||
if (!form.isValid()) { | ||
return; | ||
} | ||
|
||
void mutateAsync({ | ||
settingsKey: "crawlingAndIndexing", | ||
value: updatedValues, | ||
}); | ||
}, | ||
}); | ||
|
||
const { mutateAsync, isPending } = clientApi.serverSettings.saveSettings.useMutation({ | ||
onSettled: async () => { | ||
await revalidatePathActionAsync("/manage/settings"); | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
<Title order={2}>{t("title")}</Title> | ||
|
||
<Card pos="relative" withBorder> | ||
<Text c={"dimmed"} mb={"lg"}> | ||
{t("warning")} | ||
</Text> | ||
<LoadingOverlay visible={isPending} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} /> | ||
<Stack> | ||
<SwitchSetting form={form} formKey="noIndex" title={t("noIndex.title")} text={t("noIndex.text")} /> | ||
<SwitchSetting form={form} formKey="noFollow" title={t("noFollow.title")} text={t("noFollow.text")} /> | ||
<SwitchSetting | ||
form={form} | ||
formKey="noTranslate" | ||
title={t("noTranslate.title")} | ||
text={t("noTranslate.text")} | ||
/> | ||
<SwitchSetting | ||
form={form} | ||
formKey="noSiteLinksSearchBox" | ||
title={t("noSiteLinksSearchBox.title")} | ||
text={t("noSiteLinksSearchBox.text")} | ||
/> | ||
</Stack> | ||
</Card> | ||
</> | ||
); | ||
}; |
46 changes: 46 additions & 0 deletions
46
apps/nextjs/src/app/[locale]/manage/settings/_components/setting-switch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { ReactNode } from "react"; | ||
import React from "react"; | ||
import type { MantineSpacing } from "@mantine/core"; | ||
import { Group, Stack, Switch, Text, UnstyledButton } from "@mantine/core"; | ||
|
||
import type { UseFormReturnType } from "@homarr/form"; | ||
|
||
export const SwitchSetting = <TFormValue extends Record<string, boolean>>({ | ||
form, | ||
ms, | ||
title, | ||
text, | ||
formKey, | ||
disabled, | ||
}: { | ||
form: Omit<UseFormReturnType<TFormValue, () => TFormValue>, "setFieldValue"> & { | ||
setFieldValue: (key: keyof TFormValue, value: (previous: boolean) => boolean) => void; | ||
}; | ||
formKey: keyof TFormValue; | ||
ms?: MantineSpacing; | ||
title: string; | ||
text: ReactNode; | ||
disabled?: boolean; | ||
}) => { | ||
const handleClick = React.useCallback(() => { | ||
if (disabled) { | ||
return; | ||
} | ||
|
||
form.setFieldValue(formKey, (previous) => !previous); | ||
}, [form, formKey, disabled]); | ||
|
||
return ( | ||
<Group ms={ms} justify="space-between" gap="lg" align="center" wrap="nowrap"> | ||
<UnstyledButton style={{ flexGrow: 1 }} onClick={handleClick}> | ||
<Stack gap={0}> | ||
<Text fw="bold">{title}</Text> | ||
<Text c="gray.5" fz={{ base: "xs", md: "sm" }}> | ||
{text} | ||
</Text> | ||
</Stack> | ||
</UnstyledButton> | ||
<Switch disabled={disabled} onClick={handleClick} checked={form.values[formKey] && !disabled} /> | ||
</Group> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
import crowdinContributors from "../../../../../../../../static-data/translators.json"; | ||
|
||
export const GET = () => { | ||
return NextResponse.json(crowdinContributors); | ||
}; | ||
|
||
export const dynamic = "force-static"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
import githubContributors from "../../../../../../../../static-data/contributors.json"; | ||
|
||
export const GET = () => { | ||
return NextResponse.json(githubContributors); | ||
}; | ||
|
||
export const dynamic = "force-static"; |
33 changes: 33 additions & 0 deletions
33
apps/nextjs/src/components/layout/search-engine-optimization.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import SuperJSON from "superjson"; | ||
|
||
import { db, eq } from "@homarr/db"; | ||
import { serverSettings } from "@homarr/db/schema/sqlite"; | ||
import type { defaultServerSettings } from "@homarr/server-settings"; | ||
|
||
export const SearchEngineOptimization = async () => { | ||
const crawlingAndIndexingSetting = await db.query.serverSettings.findFirst({ | ||
where: eq(serverSettings.settingKey, "crawlingAndIndexing"), | ||
}); | ||
|
||
if (!crawlingAndIndexingSetting) { | ||
return null; | ||
} | ||
|
||
const value = SuperJSON.parse<(typeof defaultServerSettings)["crawlingAndIndexing"]>( | ||
crawlingAndIndexingSetting.value, | ||
); | ||
|
||
const robotsAttributes = [...(value.noIndex ? ["noindex"] : []), ...(value.noIndex ? ["nofollow"] : [])]; | ||
|
||
const googleAttributes = [ | ||
...(value.noSiteLinksSearchBox ? ["nositelinkssearchbox"] : []), | ||
...(value.noTranslate ? ["notranslate"] : []), | ||
]; | ||
|
||
return ( | ||
<> | ||
<meta name="robots" content={robotsAttributes.join(",")} /> | ||
<meta name="google" content={googleAttributes.join(",")} /> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.