|
1 | 1 | import { useRouter } from 'next/router'; |
| 2 | +import { heroOptions } from '../utils/hero-options'; |
2 | 3 | import Hero from './Hero'; |
3 | 4 | import Meta from './Meta'; |
4 | 5 | import Footer from './Footer'; |
5 | 6 | import styles from '../styles/Layout.module.scss'; |
6 | 7 |
|
7 | 8 | export default function Layout({ children }) { |
8 | 9 | const router = useRouter(); |
9 | | - const heroOptions = { |
10 | | - '/': { |
11 | | - imgBg: '/images/home-bg.png', |
12 | | - imgAlt: 'Homepage', |
13 | | - title: 'Web Dev Path is about', |
14 | | - dynamicTitle: 'Community', |
15 | | - content: |
16 | | - 'We help junior tech professionals, such as developers and designers, to grow.', |
17 | | - }, |
18 | | - '/about': { |
19 | | - imgBg: '/images/about-us-bg.png', |
20 | | - imgAlt: 'About Us', |
21 | | - title: 'About Us', |
22 | | - titleClass: 'accent-title', |
23 | | - content: |
24 | | - 'While the demand for web developers only increases, becoming one can be quite a journey!', |
25 | | - }, |
26 | | - '/contact': { |
27 | | - imgBg: '/images/about-us-bg.png', |
28 | | - imgAlt: 'Contact Us', |
29 | | - title: 'Contact Us', |
30 | | - titleClass: 'accent-title', |
31 | | - content: |
32 | | - 'We help junior tech professionals, such as developers and designers, to grow.', |
33 | | - }, |
34 | | - '/blog': { |
35 | | - imgBg: '/images/about-us-bg.png', |
36 | | - imgAlt: 'Blog', |
37 | | - title: 'Our Blog', |
38 | | - titleClass: 'accent-title', |
39 | | - content: |
40 | | - 'We help junior tech professionals, such as developers and designers, to grow.', |
41 | | - }, |
42 | | - '/404': { |
43 | | - imgBg: '/images/about-us-bg.png', |
44 | | - imgAlt: 'Not Found', |
45 | | - title: 'Not Found', |
46 | | - titleClass: 'accent-title', |
47 | | - content: |
48 | | - 'We help junior tech professionals, such as developers and designers, to grow.', |
49 | | - }, |
50 | | - }; |
| 10 | + const heroPathKeys = Object.keys(heroOptions) |
| 11 | + .sort((a, b) => a - b) |
| 12 | + .filter(k => router.pathname.startsWith(k)); |
| 13 | + |
| 14 | + const heroKey = heroPathKeys[heroPathKeys.length - 1]; |
51 | 15 | return ( |
52 | 16 | <> |
53 | 17 | <Meta /> |
54 | 18 | <main className={styles.main}> |
55 | | - <Hero {...heroOptions[router.pathname]} /> |
| 19 | + <Hero {...heroOptions[heroKey]} /> |
56 | 20 | {children} |
57 | 21 | <Footer /> |
58 | 22 | </main> |
|
0 commit comments