From e272afb589a3f6be590a32acccf168291ac6a7ad Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Thu, 15 Jan 2026 14:57:12 +0800 Subject: feat: Enhance HomeView component with release loading, markdown parsing, and improved UI elements --- ui/src/components/HomeView.svelte | 204 ++++++++++++++++++++++++++++++++------ 1 file changed, 175 insertions(+), 29 deletions(-) (limited to 'ui') diff --git a/ui/src/components/HomeView.svelte b/ui/src/components/HomeView.svelte index 9cd8014..2794712 100644 --- a/ui/src/components/HomeView.svelte +++ b/ui/src/components/HomeView.svelte @@ -1,47 +1,193 @@ -
- + onMount(() => { + releasesState.loadReleases(); + }); + + function formatDate(dateString: string) { + return new Date(dateString).toLocaleDateString(undefined, { + year: 'numeric', + month: 'long', + day: 'numeric' + }); + } -
+ // Enhanced markdown parser with Emoji and GitHub specific features + function formatBody(body: string) { + if (!body) return ''; + + // Emoji map (common GitHub emojis) + const emojiMap: Record = { + ':tada:': '🎉', ':sparkles:': '✨', ':bug:': '🐛', ':memo:': '📝', + ':rocket:': '🚀', ':white_check_mark:': '✅', ':construction:': '🚧', + ':recycle:': '♻️', ':wrench:': '🔧', ':package:': '📦', + ':arrow_up:': '⬆️', ':arrow_down:': '⬇️', ':warning:': '⚠️', + ':fire:': '🔥', ':heart:': '❤️', ':star:': '⭐', ':zap:': '⚡', + ':art:': '🎨', ':lipstick:': '💄', ':globe_with_meridians:': '🌐' + }; + + // Replace emojis + let processed = body.replace(/:[a-z0-9_]+:/g, (match) => emojiMap[match] || match); + + // GitHub commit hash linking (simple version for 7-40 hex chars inside backticks) + processed = processed.replace(/`([0-9a-f]{7,40})`/g, (match, hash) => { + return `${hash.substring(0, 7)}`; + }); + + // Auto-link users (@user) + processed = processed.replace(/@([a-zA-Z0-9-]+)/g, '@$1'); + + return processed.split('\n').map(line => { + line = line.trim(); + + // Formatting helper + const formatLine = (text: string) => text + .replace(/\*\*(.*?)\*\*/g, '$1') + .replace(/`([^`]+)`/g, '$1') + .replace(/\[(.*?)\]\((.*?)\)/g, '$1'); + + // Lists + if (line.startsWith('- ') || line.startsWith('* ')) { + return `
  • ${formatLine(line.substring(2))}
  • `; + } + + // Headers + if (line.startsWith('##')) { + return `

    ${line.replace(/^#+\s+/, '')}

    `; + } + if (line.startsWith('#')) { + return `

    ${line.replace(/^#+\s+/, '')}

    `; + } + + // Blockquotes + if (line.startsWith('> ')) { + return `
    ${formatLine(line.substring(2))}
    `; + } + + // Empty lines + if (line === '') return '
    '; + + // Paragraphs + return `

    ${formatLine(line)}

    `; + }).join(''); + } + + +
    + +
    -
    - -
    -

    - MINECRAFT -

    - -
    + +
    + + +
    +
    - Java Edition +
    +
    + Launcher Active +
    + +

    + MINECRAFT +

    + +
    +
    + Java Edition +
    +
    +
    + Latest Release {gameState.latestRelease?.id || '...'} +
    +
    +
    + + +
    +
    + > Ready to launch session. +
    -
    - Latest Release 1.21 + + + {#if !releasesState.isLoading && releasesState.releases.length > 0} +
    + Scroll for Updates +
    -
    + {/if}
    - -
    - -
    - Ready to play. Select version below or hit Launch. -
    + +
    +
    +

    + + LATEST UPDATES +

    + + {#if releasesState.isLoading} +
    + {#each Array(3) as _} +
    + {/each} +
    + {:else if releasesState.error} +
    + Failed to load updates: {releasesState.error} +
    + {:else if releasesState.releases.length === 0} +
    No releases found.
    + {:else} +
    + {#each releasesState.releases as release} +
    + +
    + +
    +

    + {release.name || release.tag_name} +

    +
    + + {formatDate(release.published_at)} +
    +
    + +
    +
    + {@html formatBody(release.body)} +
    +
    + + + View full changelog on GitHub + +
    + {/each} +
    + {/if} +
    -- cgit v1.2.3-70-g09d2