-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move articles to sub folder and clean up types
Also find out that the following error is not something I need to worry about: Uncaught TypeError: Cannot read properties of null (reading 'getAttribute') at link_option (utils.js?v=f20a5bac:50:11) at get_router_options (utils.js?v=f20a5bac:157:45) at preload (client.js?t=1670827563348&v=f20a5bac:1237:20) at client.js?t=1670827563348&v=f20a5bac:1202:5 link_option @ utils.js?v=f20a5bac:50 get_router_options @ utils.js?v=f20a5bac:157 preload @ client.js?t=1670827563348&v=f20a5bac:1237 (anonymous) @ client.js?t=1670827563348&v=f20a5bac:1202 setTimeout (async) (anonymous) @ client.js?t=1670827563348&v=f20a5bac:1201 ckeditor/ckeditor5#10927 And it is fixed sveltejs/kit#7913
- Loading branch information
Showing
23 changed files
with
82 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,76 @@ | ||
export type CardData = { title: string; excerpt: string; link: string, slug?: string }; | ||
|
||
export type ArticleMetaData = { | ||
metadata: { title: string; excerpt: string; slug: string; index: number }; | ||
category: string; | ||
metadata: { title: string; excerpt: string; index: number }; | ||
}; | ||
export type Article = { fileName: string } & ArticleMetaData; | ||
export type Category = { title: string; excerpt: string; slug: string }; | ||
export type Article = { | ||
fileName: string, | ||
category: string; | ||
} & ArticleMetaData; | ||
export type Category = { title: string; excerpt: string; }; | ||
export type CategoryImport = { category: Category }; | ||
const articles = import.meta.globEager('../**/*.md'); | ||
const categories = import.meta.globEager('../categories/**/index.ts'); | ||
|
||
interface Api { | ||
getCategories(): Category[]; | ||
getCategory(slug: string): Category | undefined; | ||
getCategories(): CardData[]; | ||
|
||
getCategory(slug: string): CardData | undefined; | ||
|
||
getArticles(): Article[]; | ||
getArticles(): Article[]; | ||
|
||
getArticle(name: string, category: string): Article | undefined; | ||
getArticle(name: string, category: string): Article | undefined; | ||
|
||
getArticlesByCategory(category: string): Article[]; | ||
getArticlesByCategory(category: string): CardData[]; | ||
} | ||
|
||
/** | ||
* An api object that exposes the API methods for fetching posts. | ||
*/ | ||
export const api: Api = { | ||
getCategories(): Category[] { | ||
return Object.values(categories).map((c) => (c as CategoryImport).category); | ||
}, | ||
getCategory(slug: string): Category | undefined { | ||
return this.getCategories().find((c) => c.slug.toLowerCase() === slug.toLowerCase()); | ||
}, | ||
getArticles(): Article[] { | ||
return Object.entries(articles).map(([path, article]) => { | ||
const parts = path.split('/'); | ||
const _article = article as ArticleMetaData; | ||
return { | ||
metadata: _article.metadata, | ||
fileName: `${_article.metadata.slug}`, | ||
category: parts[2] | ||
}; | ||
}); | ||
}, | ||
getArticle(name: string, category: string): Article | undefined { | ||
return this.getArticles().find( | ||
(p: Article) => | ||
p.metadata.slug.toLowerCase() === name.toLowerCase() && | ||
p.category.toLowerCase() === category.toLowerCase() | ||
); | ||
}, | ||
getArticlesByCategory(categorySlug: string): Article[] { | ||
return this.getArticles() | ||
.filter((p: Article) => p.category.toLowerCase() === categorySlug.toLowerCase()) | ||
.sort((a, b) => a.metadata.index - b.metadata.index); | ||
} | ||
getCategories(): CardData[] { | ||
return Object.entries(categories) | ||
.map(([key, c]) => { | ||
const category = (c as CategoryImport).category | ||
const slug = key.split('/')[2] | ||
return { | ||
title: category.title, | ||
excerpt: category.excerpt, | ||
link: `/articles/${slug}`, | ||
slug | ||
} | ||
}); | ||
}, | ||
getCategory(slug: string): CardData | undefined { | ||
return this.getCategories() | ||
.find((c) => c?.slug?.toLowerCase() === slug.toLowerCase()) | ||
}, | ||
getArticles(): Article[] { | ||
return Object.entries(articles).map(([path, article]) => { | ||
const parts = path.split('/'); | ||
const _article = article as ArticleMetaData; | ||
return { | ||
metadata: _article.metadata, | ||
fileName: `${parts[3].split(".")[0]}`, | ||
category: parts[2] | ||
}; | ||
}); | ||
}, | ||
getArticle(name: string, category: string): Article | undefined { | ||
return this.getArticles().find( | ||
(p: Article) => | ||
p.fileName.toLowerCase() === name.toLowerCase() && | ||
p.category.toLowerCase() === category.toLowerCase() | ||
); | ||
}, | ||
getArticlesByCategory(categorySlug: string): CardData[] { | ||
return this.getArticles() | ||
.filter((p: Article) => p.category.toLowerCase() === categorySlug.toLowerCase()) | ||
.sort((a, b) => a.metadata.index - b.metadata.index) | ||
.map((article: Article) => ({ | ||
title: article.metadata.title, | ||
excerpt: article.metadata.excerpt, | ||
link: `/articles/${categorySlug}/${article.fileName}`, | ||
})); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
title: 'How to do Smart Contracts indexing' | ||
slug: ethereumIndexing | ||
excerpt: 'Indexing smart contracts using the blockchain transaction history and bloom filters.' | ||
index: 0 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/app/src/lib/categories/software/mdsvexEthereumVisualization.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
--- | ||
title: 'Creating a Web3 modal in SvelteKit' | ||
slug: web3Modal | ||
excerpt: 'Building a web3 modal in SvelteKit' | ||
index: 0 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
4 changes: 2 additions & 2 deletions
4
...app/src/routes/[category]/+page.server.ts → ...outes/articles/[category]/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script lang="ts"> | ||
import type {CardData} from "$lib/api"; | ||
import ArticleList from "$lib/components/ArticleList.svelte"; | ||
import {api} from "$lib/api"; | ||
export let data: CardData | ||
</script> | ||
|
||
<div> | ||
<article class="prose"> | ||
<h2>{data.title}</h2> | ||
<p>{data.excerpt}</p> | ||
</article> | ||
<ArticleList articles={api.getArticlesByCategory(data.slug)}/> | ||
</div> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters