























AstraHub 星图库采用 REST API + WebSocket 的方式对外提供数据。
主题页面建议先请求状态接口,用于判断 AstraHub 插件是否已启用、星图库数据是否可用。
const statusRes = await fetch('/apis/anonymous.astrahub.halo.run/v1alpha1/star-gallery/-/status', {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: 'application/json',
},
});
if (!statusRes.ok) {
// 插件未安装、未启用,或接口不可用
}
const status = await statusRes.json();
if (!status.available) {
// 插件已启用,但星图库数据尚不可用
}
返回示例:
{
"available": true,
"generatedAt": "2026-06-28T00:00:00Z",
"relationCount": 64
}
状态可用后,请求完整快照接口。
const snapshotRes = await fetch('/apis/anonymous.astrahub.halo.run/v1alpha1/star-gallery/-/snapshot', {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: 'application/json',
},
});
const snapshot = await snapshotRes.json();
快照主要字段:
snapshot.profile // 本站 / 本星系信息snapshot.sectors // 星系联盟卡片snapshot.posts // 星际资讯每个星系卡片会提供 planetsUrl,主题可以直接请求该地址获取星系成员。
const planetsRes = await fetch(`${sector.planetsUrl}?page=1&pageSize=24`, {
method: 'GET',
credentials: 'same-origin',
headers: {
Accept: 'application/json',
},
});
const planets = await planetsRes.json();
返回示例:
{
"items": [],
"page": 1,
"pageSize": 24,
"total": 98,
"hasMore": true
}
主题可选接入 WebSocket。当 AstraHub 同步到新数据时,前台可以自动刷新星图库。
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
const ws = new WebSocket(
`${protocol}//${location.host}/apis/anonymous.astrahub.halo.run/v1alpha1/astrahub/ws/star-gallery`
);
ws.addEventListener('message', (event) => {
const snapshot = JSON.parse(event.data);
// 使用新的 snapshot 重新渲染页面
});
posts 中推荐按以下字段处理:
post.url // 文章类资讯的原文地址post.siteUrl // 星球 / 站点地址post.type // 资讯类型推荐逻辑:
const isArticle = ['rss', 'article', 'post'].includes(
String(post.type || '').toLowerCase()
);
if (isArticle && post.url) {
// 显示:打开原文
// 跳转:post.url
}
if (!isArticle && post.siteUrl) {
// 显示:定位星球
// 跳转:post.siteUrl
}
如果状态接口请求失败,主题可提示:
需要安装或启动 AstraHub 星链插件
请在 Halo 后台启用 AstraHub 星链插件,并同步星图库数据。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。