feat: include Tools in platform-grouped downloads (marqdo#110) #6

Merged
cflmy merged 2 commits from feat/tool-downloads into main 2026-12-03 11:15:01 +08:00
4 changed files with 41 additions and 16 deletions

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ const { locale, snapshot, release, asset } = Astro.props as { locale: Locale; sn
const t = <T,>(zh: T, en: T) => choose(locale, zh, en);
const withdrawn = snapshot.withdrawals.some(row => [release.release_id, asset.asset_id].includes(row.id));
const platformNames = new Map(platforms.map(platform => [platform.id as string, platform.name]));
const libraryPlatforms = archivePlatformLabel(asset.name, platformNames);
const libraryPlatforms = archivePlatformLabel(asset.name, platformNames, asset.target);
const platform = {
supported: t('已支持', 'Supported'),
'build-verified': t('仅验证构建', 'Build verified'),
+2 -2
View File
@@ -38,11 +38,11 @@ const eligibleOffers = offers.filter(offer => recommendations.has(offer.offer_id
</form>}
<section class="release-group" data-release-group>
<h2>{t('发行记录', 'Release records')}</h2>
<p>{t('组件的独立发行和生态集成状态分别显示。库发行按平台习惯提供归档:Linux → tar.gz,Windows → zip,macOS → tar.gz(同一份文件)。', 'Component releases and their ecosystem integration status appear separately. Platform-independent library archives follow platform conventions: Linux → tar.gz, Windows → zip, macOS → tar.gz (the same file).')}</p>
<p>{t('组件的独立发行和生态集成状态分别显示。平台无关库按平台习惯提供归档:Linux → tar.gz,Windows → zip,macOS → tar.gz(同一份文件);平台相关 Tool 的 tar.gz/zip 均为同一 Linux 二进制,zip 只是格式便利。', 'Component releases and their ecosystem integration status appear separately. Platform-independent library archives follow platform conventions: Linux → tar.gz, Windows → zip, macOS → tar.gz (the same file); platform-specific Tools ship the same Linux binary in both formats, where zip is only a packaging convenience.')}</p>
<p data-empty hidden={releases.length > 0}>{t('所选条件下暂无已核验的发行记录。', 'No verified release records match the selected options.')}</p>
{snapshot && releases.map(row => {
const recommended = eligibleOffers.some(offer => offer.components.some(member => member.release_id === row.release_id));
const libraryFormats = [...new Set(row.assets.flatMap(asset => archivePlatforms(asset.name)))];
const libraryFormats = [...new Set(row.assets.flatMap(asset => archivePlatforms(asset.name, asset.target)))];
const isLibrary = row.assets.every(asset => asset.target === 'source');
return <article class="divided" id={'release-' + encodeURIComponent(row.release_id)} data-release-item data-channel={row.channel} data-component={row.component_id} data-targets={row.assets.map(asset => asset.target).join(' ')} data-library={isLibrary ? '1' : undefined} data-formats={libraryFormats.join(' ')}>
<h3>{row.component_id} · {row.version}</h3>
+16 -7
View File
@@ -16,6 +16,7 @@ const products = [
const libraryGroups = [
{ kind: 'extension', label: t('扩展库', 'Extensions') },
{ kind: 'stdlib', label: t('标准库', 'Standard libraries') },
{ kind: 'tool', label: t('工具', 'Tools') },
] as const;
const snapshot = publication?.snapshot;
@@ -32,10 +33,17 @@ const downloads = (snapshot?.offers ?? []).filter(offer => recommendations.has(o
}));
const latestLibraries = new Map<string, { release: Release; assets: Asset[] }>();
const latestToolReleases = new Map<string, Release>();
for (const { release, asset } of releaseAssets) {
const kind = componentKinds.get(release.component_id);
if ((kind !== 'stdlib' && kind !== 'extension') || release.integration_state !== 'pending'
|| asset.kind !== 'archive' || asset.target !== 'source' || archivePlatforms(asset.name).length === 0) continue;
if (kind === 'tool' && archivePlatforms(asset.name, asset.target).length > 0) {
const currentTool = latestToolReleases.get(release.component_id);
if (!currentTool || Date.parse(release.published_at) > Date.parse(currentTool.published_at)) {
latestToolReleases.set(release.component_id, release);
}
}
if ((kind !== 'stdlib' && kind !== 'extension' && kind !== 'tool') || release.integration_state !== 'pending'
|| asset.kind !== 'archive' || archivePlatforms(asset.name, asset.target).length === 0) continue;
const current = latestLibraries.get(release.component_id);
if (!current || Date.parse(release.published_at) > Date.parse(current.release.published_at)) {
@@ -55,7 +63,7 @@ const noData = t('暂时无法获取下载信息。', 'Download information is t
<div class="container download-page">
<header class="download-heading">
<h1>{t('下载 ', 'Download ')}<span>Marqdo</span></h1>
<p>{t('获取应用安装包及标准库、扩展库的独立发行。', 'Get application packages and independent releases of standard and extension libraries.')}</p>
<p>{t('获取应用安装包及标准库、扩展库与工具的独立发行。', 'Get application packages and independent releases of standard libraries, extensions and tools.')}</p>
</header>
<div class="download-platforms" id="releases">
@@ -82,7 +90,7 @@ const noData = t('暂时无法获取下载信息。', 'Download information is t
<span class="download-icon-tile"><DownloadIcon name="info" size={20} /></span>
<div>
<strong>{snapshot ? t('暂无 ' + platform.name + ' 推荐安装包', 'No recommended packages for ' + platform.name) : noData}</strong>
{[...latestLibraries.values()].some(({ assets }) => assets.some(asset => archivePlatforms(asset.name).includes(platform.id))) && (
{[...latestLibraries.values()].some(({ assets }) => assets.some(asset => archivePlatforms(asset.name, asset.target).includes(platform.id))) && (
<p>{t('下方仍可下载此平台适用的库归档。', 'You can still download library archives for this platform below.')}</p>
)}
</div>
@@ -133,15 +141,16 @@ const noData = t('暂时无法获取下载信息。', 'Download information is t
</section>
<section class="download-section" aria-labelledby="library-downloads">
<h2 id="library-downloads">{t('标准库与扩展库', 'Standard and extension libraries')}</h2>
<h2 id="library-downloads">{t('标准库、扩展库与工具', 'Libraries and tools')}</h2>
{platforms.map(platform => {
const groups = libraryGroups.map(group => ({
...group,
entries: [...latestLibraries.values()]
.filter(({ release }) => componentKinds.get(release.component_id) === group.kind)
.flatMap(({ release, assets }) => {
const asset = assets.find(item => archivePlatforms(item.name).includes(platform.id));
return asset ? [{ release, asset }] : [];
return assets
.filter(item => archivePlatforms(item.name, item.target).includes(platform.id))
.map(asset => ({ release, asset }));
})
.sort((left, right) => left.release.component_id.localeCompare(right.release.component_id)),
})).filter(group => group.entries.length > 0);
+22 -6
View File
@@ -27,14 +27,30 @@ export function assetDescription(target: string, filename: string) {
return [platform, format].filter(Boolean).join(' · ');
}
/** Platform conventions for platform-independent library archives. */
export function archivePlatforms(filename: string): readonly Platform[] {
/**
* Platforms an archive is offered for.
*
* - Platform-independent components (asset target `source`): the tar.gz follows
* the Linux/POSIX and macOS conventions, the zip follows Windows.
* - Platform-specific components (Tools): tar.gz and zip carry the same target
* binary, so the target platform applies and the format is only a packaging
* convenience (a zip is never implied to be a Windows binary).
*/
export function archivePlatforms(filename: string, target = 'source'): readonly Platform[] {
const lower = filename.toLowerCase();
return platforms.filter(platform => lower.endsWith(platform.libraryFormat)).map(platform => platform.id);
const isArchive = lower.endsWith('.tar.gz') || lower.endsWith('.zip');
if (!isArchive) return [];
if (target !== 'source') {
const platform = releaseTargets.get(target)?.[0];
return platform ? [platform] : [];
}
return platforms
.filter(platform => lower.endsWith(platform.libraryFormat))
.map(platform => platform.id);
}
/** Human label for the platforms a library archive is offered for. */
export function archivePlatformLabel(filename: string, names: ReadonlyMap<string, string>): string {
const ids = archivePlatforms(filename);
/** Human label for the platforms an archive is offered for. */
export function archivePlatformLabel(filename: string, names: ReadonlyMap<string, string>, target = 'source'): string {
const ids = archivePlatforms(filename, target);
return ids.map(id => names.get(id) ?? id).join(' · ');
}