Skip to content

Commit

Permalink
fix(example): add isCurrentPath function comparing current url to loc…
Browse files Browse the repository at this point in the history
…alized path
  • Loading branch information
yassinedoghri committed Aug 21, 2022
1 parent 6884c7c commit ee90afb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 45 deletions.
13 changes: 11 additions & 2 deletions example/src/components/molecules/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import i18next, { t } from "i18next";
import { localizePath } from "astro-i18next";
const { ...attributes } = Astro.props;
const { pathname } = Astro.url;
// TODO: add as a utility function for astro-i18next. (out of scope?)
const isCurrentPath = (path: string) => {
const { pathname } = Astro.url;
const currentNormalizedPath = pathname.replace(/\/$/, "");
path = path.replace(/\/$/, "");
return currentNormalizedPath === path;
};
const navigationItems = {
"/": t("navigation.home"),
Expand All @@ -15,7 +24,7 @@ const navigationItems = {
{Object.keys(navigationItems).map((key) => {
let className =
"py-2 px-4 uppercase text-sm underline-offset-2 tracking-wider decoration-4 font-semibold";
if (localizePath(key, i18next.language) === pathname) {
if (isCurrentPath(localizePath(key, i18next.language))) {
className += " underline decoration-cyan-500";
} else {
className +=
Expand Down
24 changes: 0 additions & 24 deletions example/src/pages/en/about.astro

This file was deleted.

19 changes: 0 additions & 19 deletions example/src/pages/en/index.astro

This file was deleted.

1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import typescript from "@proload/plugin-typescript";
* Adapted from astro's tailwind integration:
* https://github.com/withastro/astro/tree/main/packages/integrations/tailwind
*/
/* istanbul ignore next */
export const getUserConfig = async (
root: URL,
configPath?: string
Expand Down

0 comments on commit ee90afb

Please sign in to comment.