diff --git a/src/pages/index.astro b/src/pages/index.astro index 941b1e9..73288e8 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -14,7 +14,7 @@ import cv from '@/data'; const { config, sections } = cv(); --- - +
diff --git a/src/types/data.ts b/src/types/data.ts index 5dbfd77..5276a3f 100644 --- a/src/types/data.ts +++ b/src/types/data.ts @@ -9,7 +9,7 @@ import type { PortfolioSection } from './sections/portfolio-section.types'; import type { SkillsSection } from './sections/skills-section.types'; import type { TestimonialsSection } from './sections/testimonials-section.types'; -export interface Config { +export type Config = { /** * [WEB] Page metadata used for SEO and social media sharing. */ @@ -24,9 +24,9 @@ export interface Config { * [PDF] Configuration of the pdf generation. */ pdf?: PdfConfig; -} +}; -export interface Sections { +export type Sections = { /** * Basic information about you. */ @@ -61,7 +61,7 @@ export interface Sections { * [WEB] List of sources you use to gain knowledge and inspiration. */ favorites: FavoritesSection; -} +}; /** * All data used to generate the cv. diff --git a/src/web/components/layout.astro b/src/web/components/layout.astro index 54bd7dc..4c96e8d 100644 --- a/src/web/components/layout.astro +++ b/src/web/components/layout.astro @@ -1,15 +1,17 @@ --- -import type { Data } from '@/types/data'; +import type { Config, Sections } from '@/types/data'; import Head from '@/web/head/head.astro'; -export interface Props extends Pick {} +export interface Props extends Config { + sections: Sections; +} -const { meta, i18n } = Astro.props; +const { meta, i18n, sections } = Astro.props; --- - + diff --git a/src/web/head/head.astro b/src/web/head/head.astro index 6ef4c8d..382368d 100644 --- a/src/web/head/head.astro +++ b/src/web/head/head.astro @@ -1,20 +1,24 @@ --- import Fonts from '@/components/fonts.astro'; import type { MetaConfig } from '@/types/config/meta-config.types'; +import type { Sections } from '@/types/data'; import Favicons from './favicons.generated.astro'; +import InitialHash from './initial-hash.astro'; import InitialTheme from './initial-theme.astro'; import Meta from './meta.astro'; interface Props { meta: MetaConfig; + sections: Sections; } -const { meta } = Astro.props; +const { meta, sections } = Astro.props; --- + diff --git a/src/web/head/initial-hash.astro b/src/web/head/initial-hash.astro new file mode 100644 index 0000000..3a978ba --- /dev/null +++ b/src/web/head/initial-hash.astro @@ -0,0 +1,17 @@ +--- +import type { Sections } from '@/types/data'; + +interface Props { + sections: Sections; +} + +const { sections } = Astro.props; + +const firstVisibleSection = Object.values(sections).find((section) => section.config.visible); +const firstVisibleSectionSlug = firstVisibleSection?.config.slug; +--- + +{/* Used in src/web/utils/hash-state.ts */} + diff --git a/src/web/utils/hash-state.ts b/src/web/utils/hash-state.ts index 44a75f0..6013eaf 100644 --- a/src/web/utils/hash-state.ts +++ b/src/web/utils/hash-state.ts @@ -1,14 +1,14 @@ -import sections from '@/data/sections'; import { isServer } from './env'; +// Set in src/web/head/initial-hash.astro +declare let window: Window & { firstVisibleSectionSlug?: string }; + const getInitialHash = () => { if (isServer) return ''; - const firstVisibleSection = Object.values(sections).find((section) => section.config.visible); + if (window.location.hash) return window.location.hash; - if (!firstVisibleSection) return ''; - - return window.location.hash || `#${firstVisibleSection.config.slug}`; + return window.firstVisibleSectionSlug ? `#${window.firstVisibleSectionSlug}` : ''; }; const createHashState = () => {