svelte-society / sveltesociety.dev

The Svelte Society website
https://sveltesociety.dev/
MIT License
369 stars 215 forks source link

[V2] Service to load data from different sources #641

Open MacFJA opened 4 months ago

MacFJA commented 4 months ago

🎯 Changes

This PR add "service" to load data from sources (internal and external).

Implemented source:

[^1]: There is no public API, the probability that the current code won't work in a near future is pretty high :disappointed: [^2]: Need to be connected to the database

Usage

Server side

The input data is minimal: the type of data and an identifier.

Each source will be interrogated if it can handle the data

await collectorService.getAllInformation([
    { type: 'package', identifier: '@sveltejs/kit' },
    { type: 'video', identifier: 'xCeYmdukOKI' },
])
// This will return 2 objects with an known structure

[!NOTE] CollectorService is a service that aggregate all main service

All services will be asked if they can handle a package, that can be found with an identifier (so Youtube service will respond immediately that it can't and package)

[!TIP] All methods that request external resource or take time to compute can be cached with the addition of a simple decorator (@Memorize(cacheStorage)) to reduce lantency

Render side

To display a data from the services, there are 5 components:

All components are design to accept the same parameter as the result of the services, so using them is simple: +page.svelte

    {#if item.type === 'package'}
        <PackageCard
            {...item}
            title={item.name}
            time={item.lastUpdate}
            tags={item.keywords.map((i) => ({ id: i, name: i }))}
        />
    {:else if item.type === 'video'}
        <VideoCard
            {...item}
            title={item.name}
            time={item.lastUpdate}
            tags={item.keywords.map((i) => ({ id: i, name: i }))}
        />
    {:else if item.type === 'recipe'}
        <RecipeCard
            {...item}
            title={item.name}
            time={item.lastUpdate}
            tags={item.keywords.map((i) => ({ id: i, name: i }))}
        />
    {:else if item.type === 'guild'}
        <GuildCard {...item} title={item.name} time={item.lastUpdate} tags={[]} />
    {:else if item.type === 'guild-event'}
        <GuildEventCard {...item} title={item.name} />
    {/if}
vercel[bot] commented 4 months ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
sveltesociety-dev ❌ Failed (Inspect) Jul 8, 2024 5:14pm
sveltesociety-dev-preview ❌ Failed (Inspect) Jul 8, 2024 5:14pm
sveltesociety-v2 βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jul 8, 2024 5:14pm
cloudflare-workers-and-pages[bot] commented 4 months ago

Deploying sveltesociety with  Cloudflare Pages  Cloudflare Pages

Latest commit: a92128c
Status:🚫  Build failed.

View logs