feat: order blog entrys by date and direct link if source is available
This commit is contained in:
@@ -3,23 +3,30 @@
|
||||
import type { SvelteComponent } from 'svelte';
|
||||
import './style-entries.css';
|
||||
|
||||
const blog_entries: [string, SvelteComponent][] = Object.entries(
|
||||
let blog_entries: [string, SvelteComponent][] = Object.entries(
|
||||
import.meta.glob('/src/routes/blogs/**/+page.svx', { eager: true })
|
||||
).map(([key, value]) => [
|
||||
key.split('/src/routes').pop()?.split('/+page.svx').slice(0, -1).pop() as string,
|
||||
value as MDsveXComponent
|
||||
]);
|
||||
]).map(([link,val])=>
|
||||
typeof val.metadata?.src !== 'undefined' ? [val.metadata?.src, val] : [link,val]
|
||||
).map(([link,val])=>{
|
||||
if(val.metadata)
|
||||
val.metadata.date = Date.parse(val.metadata?.date);
|
||||
return [link,val];
|
||||
}
|
||||
).sort(([link1,a],[link2,b])=>b.metadata?.date-a.metadata?.date);
|
||||
console.log(blog_entries);
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<div class="start">
|
||||
<h1>Welcome to SvelteKit</h1>
|
||||
<h1>Welcome to SvelteKit</h1>
|
||||
<p>
|
||||
Visit <a href="https://svelte.dev/docs/kit">svelte.dev/docs/kit</a> to read the documentation
|
||||
</p>
|
||||
</div>
|
||||
{#each blog_entries as [href, page]}
|
||||
{#each blog_entries as [href, page]}
|
||||
<a {href}>
|
||||
<div class="blog-entry">
|
||||
<div>
|
||||
@@ -32,7 +39,7 @@
|
||||
</a>
|
||||
<br />
|
||||
<!-- svelte:component this={page.default} /-->
|
||||
{/each}
|
||||
{/each}
|
||||
</main>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user