Skip to content

Commit ed55b53

Browse files
committed
refactor: reorganize texts
1 parent 94fc462 commit ed55b53

File tree

11 files changed

+135
-71
lines changed

11 files changed

+135
-71
lines changed

packages/shared/config/astro.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ import icon from 'astro-icon'
22
import tailwind from '@astrojs/tailwind'
33
import type { AstroUserConfig } from 'astro/config'
44

5-
import { PROJECTS_URL } from '../consts'
5+
import { API_URL } from '../consts'
66

7-
export function getAstroConfig ({ project }: { project?: string } = {}): AstroUserConfig {
7+
export interface GetAstroConfig {
8+
project?: string
9+
}
10+
11+
export function getAstroConfig ({ project }: GetAstroConfig = {}): AstroUserConfig {
12+
const assets = 'assets'
13+
const { hostname } = new URL(API_URL)
814
const hasProjectName = typeof project === 'string'
9-
const { hostname } = new URL(PROJECTS_URL)
15+
const outDir = hasProjectName ? `../../dist/${project}` : undefined
16+
const base = hasProjectName ? `/frontendmentor/${project}` : '/frontendmentor'
1017

1118
return {
19+
base,
20+
outDir,
1221
integrations: [tailwind(), icon()],
13-
base: hasProjectName ? `/frontendmentor/${project}` : '/frontendmentor',
14-
outDir: hasProjectName ? `../../dist/${project}` : undefined,
1522
build: {
16-
assets: 'assets'
23+
assets
1724
},
1825
image: {
1926
domains: [hostname]

packages/shared/consts.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import { cwd } from 'node:process'
21
import { loadEnv } from 'vite'
32

4-
const PROJECT_NAME = 'frontendmentor'
5-
6-
const envDirectory = cwd().split(PROJECT_NAME)[0] + PROJECT_NAME
7-
const { API_PROJECTS_URL } = loadEnv('', envDirectory, 'API')
8-
9-
export const PROJECTS_URL = API_PROJECTS_URL
3+
export const { PUBLIC_API_URL: API_URL, PUBLIC_FRONTENDMENTOR_URL: FRONTENDMENTOR_URL } = loadEnv('', '', 'PUBLIC')

packages/shared/utils/http.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export async function get<T>(urlRequest: string): Promise<T> {
2+
const response = await fetch(urlRequest)
3+
return (await response.json()) as T
4+
}

src/components/Card.astro

+9-6
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ import Tech from '@/components/Tech.astro'
66
import LevelTag from '@/components/LevelTag.astro'
77
88
interface Props {
9-
title: string
10-
link: string
11-
level: number
9+
level: {
10+
link: string
11+
name: string
12+
number: number
13+
}
1214
image: string
15+
link: string
1316
techs: string[]
17+
title: string
1418
}
1519
1620
const { image: source, level, link, title, techs } = Astro.props
1721
1822
const techsGridAlign = 'grid grid-rows-2 gap-y-3'
1923
const techsFlexAlign = 'flex flex-wrap items-center justify-between'
20-
const levelSearchLink = `https://www.frontendmentor.io/challenges?difficulty=${level}&sort=difficulty%7Casc`
2124
const cardShadowClass =
2225
'before:pointer-events-none before:absolute before:top-0 before:z-10 before:h-24 before:w-full before:bg-[linear-gradient(rgba(0,0,0,0.15),rgba(0,0,0,0))] before:content-[""]'
2326
---
@@ -38,8 +41,8 @@ const cardShadowClass =
3841
<div class="flex gap-x-1.5 md:gap-x-2.5">
3942
{techs.map((tech) => <Tech name={tech} />)}
4043
</div>
41-
<Link external to={levelSearchLink} class="justify-self-end">
42-
<LevelTag {level} />
44+
<Link external to={level.link} class="justify-self-end">
45+
<LevelTag level={level.number} name={level.name} />
4346
</Link>
4447
</article>
4548
</section>

src/components/Footer.astro

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
---
22
import Link from 'shared/components/Link.astro'
3+
4+
interface Props {
5+
designedBy: {
6+
link: string
7+
text: string
8+
}
9+
developedBy: {
10+
link: string
11+
text: string
12+
}
13+
}
14+
15+
const { designedBy, developedBy } = Astro.props
316
---
417

518
<footer class="border-y border-gray-300 bg-white">
619
<div
720
class="mx-auto flex max-w-[75rem] flex-col justify-center gap-y-3 p-6 text-center md:flex-row md:justify-between"
821
>
922
<p>
10-
Design is property of <Link external to="https://www.frontendmentor.io/" class="font-bold hover:underline">
11-
Frontend Mentor
23+
Design is property of <Link external to={designedBy.link} class="font-bold hover:underline">
24+
{designedBy.text}
1225
</Link>
1326
</p>
1427
<p>
15-
Developed by <Link external to="https://erian.dev/" class="font-semibold text-html hover:underline">
16-
@eriandev
28+
Developed by <Link external to={developedBy.link} class="font-semibold text-html hover:underline">
29+
{developedBy.text}
1730
</Link>
1831
</p>
1932
</div>

src/components/Header.astro

+19-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ import Link from 'shared/components/Link.astro'
33
import Icon from 'shared/components/Icon.astro'
44
import Image from 'shared/components/Image.astro'
55
6-
const navigation = [
7-
{ to: '/', external: false, text: 'My Solutions' },
8-
{ to: 'https://www.frontendmentor.io/challenges', external: true, text: 'Challenges' },
9-
{ to: 'https://www.frontendmentor.io/resources', external: true, text: 'Resources' },
10-
]
6+
interface Props {
7+
navigation: Array<{
8+
external: boolean
9+
text: string
10+
to: string
11+
}>
12+
profile: {
13+
image: {
14+
src: string
15+
alt: string
16+
}
17+
link: string
18+
title: string
19+
}
20+
}
21+
22+
const { navigation, profile } = Astro.props
1123
12-
const src = '/frontendmentor/images/profile-image.webp'
13-
const profileLink = 'https://www.frontendmentor.io/profile/eriandev'
1424
const linkClass =
1525
'relative after:absolute after:-bottom-1 after:left-0 after:h-0.5 after:w-full after:scale-0 after:bg-guru after:content-[""] after:[transition:transform_0.3s_ease_0s] hover:after:scale-100 hover:after:[transition:transform_0.3s_ease_0s]'
1626
---
@@ -32,8 +42,8 @@ const linkClass =
3242
}
3343
</ul>
3444
</nav>
35-
<Link external title="Go to my frontendmentor profile" to={profileLink}>
36-
<Image {src} width={42} height={42} alt="Profile image" class="rounded-full" />
45+
<Link external title={profile.title} to={profile.link}>
46+
<Image src={profile.image.src} width={42} height={42} alt={profile.image.alt} class="rounded-full" />
3747
</Link>
3848
</section>
3949
</div>

src/components/LevelTag.astro

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
---
22
interface Props {
33
level: number
4+
name: string
45
class?: string
56
}
67
7-
const { level, class: extraClass } = Astro.props
8+
const { level, name, class: extraClass } = Astro.props
89
9-
const LEVELS = ['newbie', 'junior', 'intermediate', 'advanced', 'guru']
10-
const levelColor = LEVELS[level - 1]
11-
const bgColor = 'bg-' + levelColor
12-
const textColor = 'text-' + levelColor
13-
const borderColor = 'border-' + levelColor
10+
const bgColor = 'bg-' + name
11+
const textColor = 'text-' + name
12+
const borderColor = 'border-' + name
1413
---
1514

1615
<div
1716
class:list={[
18-
borderColor,
1917
'flex h-max w-max items-center rounded-md border text-xs font-bold leading-5 md:text-sm md:leading-6',
18+
borderColor,
2019
extraClass,
2120
]}
2221
>
2322
<span class:list={[bgColor, 'block h-full rounded-l-sm px-2 text-white md:px-3']}>
2423
{level}
2524
</span>
2625
<span class:list={[textColor, 'block px-1.5 uppercase md:px-3']}>
27-
{levelColor}
26+
{name}
2827
</span>
2928
</div>

src/env.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
/// <reference path="../.astro/types.d.ts" />
22
/// <reference types="astro/client" />
3+
4+
interface ImportMetaEnv {
5+
readonly PUBLIC_API_URL: string
6+
}
7+
8+
interface ImportMeta {
9+
readonly env: ImportMetaEnv
10+
}

src/layouts/Layout.astro

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
---
2+
import { get } from 'shared/utils/http'
3+
import { API_URL } from 'shared/consts'
24
import MetaTags from 'shared/components/MetaTags.astro'
5+
36
import Header from '@/components/Header.astro'
7+
import Footer from '@/components/Footer.astro'
8+
9+
interface Landing {
10+
header: {
11+
navigation: Array<{
12+
external: boolean
13+
text: string
14+
to: string
15+
}>
16+
profile: {
17+
image: {
18+
src: string
19+
alt: string
20+
}
21+
link: string
22+
title: string
23+
}
24+
}
25+
26+
footer: {
27+
designedBy: {
28+
link: string
29+
text: string
30+
}
31+
developedBy: {
32+
link: string
33+
text: string
34+
}
35+
}
36+
}
37+
38+
const { footer, header } = await get<Landing>(API_URL + '/landing/')
39+
const { designedBy, developedBy } = footer
40+
const { navigation, profile } = header
441
---
542

643
<!doctype html>
@@ -44,7 +81,8 @@ import Header from '@/components/Header.astro'
4481
</head>
4582

4683
<body class="min-h-screen bg-gray-100 font-barlow font-medium text-black">
47-
<Header />
84+
<Header {navigation} {profile} />
4885
<slot />
86+
<Footer {designedBy} {developedBy} />
4987
</body>
5088
</html>

src/pages/index.astro

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
---
2+
import { get } from 'shared/utils/http'
3+
import { API_URL } from 'shared/consts'
4+
25
import Card from '@/components/Card.astro'
36
import Layout from '@/layouts/Layout.astro'
4-
import Footer from '@/components/Footer.astro'
5-
import { getProjects } from '@/services/projects'
67
7-
const projects = await getProjects()
8-
const hasProjects = projects.length > 0
8+
interface Projects {
9+
level: {
10+
link: string
11+
name: string
12+
number: number
13+
}
14+
image: string
15+
link: string
16+
techs: string[]
17+
title: string
18+
}
19+
20+
const { results } = await get<{ results: Projects[] }>(API_URL + '/projects/')
21+
const hasProjects = results.length > 0
922
---
1023

1124
<Layout title="Frontendmentor Challenges Solved">
@@ -24,12 +37,10 @@ const hasProjects = projects.length > 0
2437
>
2538
{
2639
hasProjects ? (
27-
projects.map((projectData) => <Card {...projectData} />)
40+
results.map((projectData) => <Card {...projectData} />)
2841
) : (
2942
<p class="mx-auto w-max text-2xl md:text-3xl">No projects to show...</p>
3043
)
3144
}
3245
</main>
33-
34-
<Footer />
3546
</Layout>

src/services/projects.ts

-23
This file was deleted.

0 commit comments

Comments
 (0)