Skip to content

Commit

Permalink
feat(project): akthualey use typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
fourstepper committed Dec 16, 2023
1 parent e7b6c4d commit f91aea9
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Theme = "system" | "light" | "dark";

interface PostMetadata {
interface Post {
slug: string;
title: string;
date: DateConstructor;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Footer.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
const currentYear = new Date().getFullYear();
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const RSS = async () => {
};

//Be sure to review and replace any applicable content below!
const render = (posts: any) => `<?xml version="1.0" encoding="UTF-8" ?>
const render = (posts: Post[]) => `<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>${siteTitle}</title>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/posts.json/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export const prerender = true;
export const GET = async () => {
const options = {};

const { posts } = await fetchPosts(options);
const { posts }: { posts: Post[] } = await fetchPosts(options);
return json(posts);
};
2 changes: 1 addition & 1 deletion src/routes/posts/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import PostsList from "$lib/components/PostsList.svelte";
import { siteTitle } from "$lib/config";
Expand Down
4 changes: 2 additions & 2 deletions src/routes/posts/tags/+page.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const load = async ({ url, fetch }: { url: URL; fetch: any }) => {
const postRes = await fetch(`${url.origin}/api/posts.json`);
const posts = await postRes.json();
const posts: Post[] = await postRes.json();

let uniqueTags: string[] = [];
let uniqueTags: Post["tags"] = [];

for (let post of posts) {
if (!post.tags) {
Expand Down
12 changes: 6 additions & 6 deletions src/routes/posts/tags/[tag]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<PostsList posts={data.filteredPosts} />

<style lang="scss">
span {
color: getColor(red);
}
h1 {
margin-bottom: 0;
}
span {
color: getColor(red);
}
h1 {
margin-bottom: 0;
}
</style>
20 changes: 14 additions & 6 deletions src/routes/posts/tags/[tag]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
export const load = async ({ url, fetch, params }: { url: URL; fetch: any, params: any }) => {
export const load = async ({
url,
fetch,
params,
}: {
url: URL;
fetch: any;
params: any;
}) => {
const postRes = await fetch(`${url.origin}/api/posts.json`);
const posts = await postRes.json();
const posts: Post[] = await postRes.json();

let filteredPosts : any = []
let filteredPosts: Post[] = [];

for (let post of posts) {
if (post.tags && post.tags.includes(params.tag)) {
filteredPosts.push(post)
}
if (post.tags && post.tags.includes(params.tag)) {
filteredPosts.push(post);
}
}

return { filteredPosts, params };
Expand Down
1 change: 0 additions & 1 deletion src/routes/rss.xml/+server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { siteTitle, siteDescription, siteURL, siteLink } from "$lib/config";
import RSS from "$lib/helpers/rss";

export const prerender = true;
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
// "dom" added based on https://github.com/DefinitelyTyped/DefinitelyTyped/issues/19799
"lib": [ "es2017", "dom"],
"module": "es2022",
"moduleResolution": "Node",
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
Expand Down

0 comments on commit f91aea9

Please sign in to comment.