Skip to content

Commit

Permalink
fix: Update consts, nav-link component
Browse files Browse the repository at this point in the history
- Remove unused consts
- Fix nav-link not showing active state when i18n lang param present
  • Loading branch information
kiosion committed Oct 2, 2023
1 parent 134d7d6 commit 267a203
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 43 deletions.
5 changes: 3 additions & 2 deletions svelte-app/src/components/nav/nav-link.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
goto($linkTo(link.url)).catch(() => undefined);
};
$: splitPath = $page?.url.pathname.split('/') || [];
$: splitPath = $page?.url?.pathname?.split('/') || [];
$: (isActive = (() => {
let urlIncludesLink = $page?.url.pathname === link.url;
let urlIncludesLink =
($isLocalized ? $page?.url?.pathname?.slice(3) : $page?.url?.pathname) === link.url;
if (navigatingIsActive) {
urlIncludesLink ||= $navigating?.to?.url.pathname === link.url;
Expand Down
35 changes: 4 additions & 31 deletions svelte-app/src/lib/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,29 @@ export const NAV_LINKS = TOP_LEVEL_ROUTES.filter((route) => !route.hidden)?.map(
export const BASE_TRANSITION_DURATION = 200 as const;
export const BASE_ANIMATION_DURATION = 300 as const;

export const PAGINATION_POSTS_PER_PAGE = 12;
export const PAGINATION_PROJECTS_PER_PAGE = 12;
export const HOMEPAGE_POSTS_NUM = 4 as const;
export const HOMEPAGE_PROJECTS_NUM = 1 as const;

// Disable pagination for now
export const RECENT_POSTS_COUNT = 99;
export const RECENT_PROJECTS_COUNT = 99;

export const DEFAULT_POST_QUERY_PARAMS = {
limit: PAGINATION_POSTS_PER_PAGE,
limit: 99,
skip: 0,
sort: 'date',
order: 'desc',
date: '',
tags: []
};

export const DEFAULT_PROJECT_QUERY_PARAMS = {
...DEFAULT_POST_QUERY_PARAMS,
limit: PAGINATION_PROJECTS_PER_PAGE
};
export const DEFAULT_PROJECT_QUERY_PARAMS = DEFAULT_POST_QUERY_PARAMS;

export const DEFAULT_DESKTOP_WIDTH = 768;
export const DEFAULT_MOBILE_WIDTH = DEFAULT_DESKTOP_WIDTH - 1;

export const DEFAULT_DESKTOP_BREAKPOINT = `(min-width: ${DEFAULT_DESKTOP_WIDTH}px)`;
export const DEFAULT_MOBILE_BREAKPOINT = `(max-width: ${DEFAULT_MOBILE_WIDTH}px)`;

export const DEFAULT_BREAKPOINTS = {
sm: DEFAULT_MOBILE_BREAKPOINT,
lg: DEFAULT_DESKTOP_BREAKPOINT
};

export const LANGUAGE_COLOURS = new Proxy(
new Map([
['asp', '#6a40fd'],
Expand Down Expand Up @@ -157,21 +148,3 @@ export const LANGUAGE_COLOURS = new Proxy(
}
}
);

export const LOADING_PHRASES = [
'Spinning violently around the y-axis',
'Assembling from source',
'Hunting for bugs',
'Dusting the cobwebs',
'Looking for missing semicolons',
':3',
'Calculating the airspeed velocity of an unladen swallow',
'Brewing some coffee',
'Browsing StackOverflow',
'Warming up your CPU',
'Rotating the earth',
'Decompiling binaries',
'RTFM-ing',
'Parsing XML',
'Grokking the hypersphere'
];
4 changes: 2 additions & 2 deletions svelte-app/src/routes/[[lang=lang]]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DEFAULT_APP_LANG } from '$lib/consts';
import { DEFAULT_APP_LANG, HOMEPAGE_POSTS_NUM } from '$lib/consts';
import { find, findOne } from '$lib/store';

import { error } from '@sveltejs/kit';
Expand All @@ -11,7 +11,7 @@ export const load = (async ({ parent, fetch, params }) => {
about = parentData.about,
lang = params.lang || DEFAULT_APP_LANG,
promiseArray = [
find(fetch, 'post', { limit: 6, lang }),
find(fetch, 'post', { limit: HOMEPAGE_POSTS_NUM, lang }),
findOne(fetch, 'project', { id: 'kio.dev', lang })
];

Expand Down
4 changes: 2 additions & 2 deletions svelte-app/src/routes/[[lang=lang]]/blog/+page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { RECENT_POSTS_COUNT } from '$lib/consts';
import { DEFAULT_POST_QUERY_PARAMS } from '$lib/consts';
import { find } from '$lib/store';

import type { PageLoad } from './$types';

export const load = (async ({ fetch, params }) => {
const posts = await find(fetch, 'post', {
limit: RECENT_POSTS_COUNT,
...DEFAULT_POST_QUERY_PARAMS,
lang: params.lang ?? 'en'
});

Expand Down
7 changes: 1 addition & 6 deletions svelte-app/src/routes/[[lang=lang]]/work/+page.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
DEFAULT_APP_LANG,
DEFAULT_PROJECT_QUERY_PARAMS,
RECENT_PROJECTS_COUNT
} from '$lib/consts';
import { DEFAULT_APP_LANG, DEFAULT_PROJECT_QUERY_PARAMS } from '$lib/consts';
import { find } from '$lib/store';

import { error } from '@sveltejs/kit';
Expand All @@ -14,7 +10,6 @@ export const load = (async ({ parent, fetch, params }) => {
lang = params.lang || DEFAULT_APP_LANG,
projects = await find(fetch, 'project', {
...DEFAULT_PROJECT_QUERY_PARAMS,
limit: RECENT_PROJECTS_COUNT,
lang
});

Expand Down

0 comments on commit 267a203

Please sign in to comment.