惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

Mikuの极光星

用 Codex 写了一个 Noctalia 插件 Process Reporter | Mikuの极光星 荣耀 X16 锐龙版(2024)运行 Linux 问题和修复 | Mikuの极光星 Noctalia Plugin Linuxwallpaperengine | Mikuの极光星 Love Love School Days 在 Linux 下游戏汉化补丁安装使用 | Mikuの极光星 Fedora Silverblue 安装记录和不可变 Linux 个人杂谈 | Mikuの极光星 国内外主流对象存储价格对比 | Mikuの极光星 随笔:逝去的一段时光 | Mikuの极光星 Riddle Joker:剧情不足,人设也不足 | Mikuの极光星 在 CachyOS Handheld 下恢复 Steam Input 中文输入 | Mikuの极光星 Fedora Cosmic desktop Beta 一日游 | Mikuの极光星 博客~真周年随笔(大概是一周年) | Mikuの极光星 Waline-Mini 部署体验:基于 Rust 的 Waline 评论系统? | Mikuの极光星 迟来的个人对《拔作岛》第一部游戏动漫杂谈 | Mikuの极光星 OtterWiki 部署:基于 Python 的轻量知识库系统 | Mikuの极光星 Mikuの极光星 Mikuの极光星 Mikuの极光星 Mikuの极光星 我的 KDE Plasma 6 美化方案分享 | Mikuの极光星 Mikuの极光星 自建一个 Fediverse 实例,我们需要准备什么? | Mikuの极光星 Decky Loader——Linux下 Steamdeck 和大屏幕模式的最佳伴侣 | Mikuの极光星 更换网站字体为霞鹜文楷屏幕阅读版(LXGW WenKai Screen) | Mikuの极光星 《Clannad》HD 官方中文版和 Full Voice 汉化版 Linux 运行 | Mikuの极光星 《恋爱与选举与巧克力》携带版试玩体验 | Mikuの极光星 我又用了一段时间 Misskey,发现和 Sharkey 存在一些区别和不足 | Mikuの极光星 Misskey/Sharkey 工具栏:强大且精心的小功能 | Mikuの极光星 浅谈个人与 Fediverse 的过往历史和现状 | Mikuの极光星 《爱上火车》在 Linux 下的视频播放修复 | Mikuの极光星 旮沓给木太好玩辣——2025年上半Gal历程个人总结 | Mikuの极光星
Mikuの极光星
Mikuの鬆, admin@sotkg.com · 2025-10-20 · via Mikuの极光星

跳转到主要内容 / Skip to content

本文介绍了为Clarity博客主题增加ResourceList资源列表组件的方法,提供了完整的Vue组件代码与使用语法,用于创建包含标题、链接、密码等信息的资源下载列表。

前言

本站使用的是纸鹿的 Clarity 博客主题(个人修改)版,最近加上了一个资源列表和下载组件,用来替换部分页面组件和未来准备的可能性下载需求。

本篇文章讲解如何添加和使用本组件到 Clarity 主题博客中。

组件文件

/app/components/content/ 目录下新建 ResourceList.vue 并填入以下代码:

Github Gist

https://gist.github.com/PaloMiku/11e5c3e6ccdad906e0dca2aea26228ba

本站

vue
<script setup lang="ts">
interface ResourceItem {
  id?: string | number
  title: string
  subtitle?: string
  tags?: string[]
  link?: string
  summary?: string
  extractPassword?: string
  downloadPassword?: string
}

defineProps<{
  items: ResourceItem[]
}>()
</script>

<template>
<ol class="resource-list">
	<li v-for="item in items" :key="item.id ?? item.title" class="resource-item card">
		<div class="resource-content">
			<div>
				<div class="resource-title">
					{{ item.title }}
				</div>
				<p v-if="item.subtitle" class="resource-subtitle">
					{{ item.subtitle }}
				</p>
				<p v-if="item.summary" class="resource-summary">
					{{ item.summary }}
				</p>
			</div>

			<div class="resource-meta">
				<div v-if="item.extractPassword || item.downloadPassword" class="passwords">
					<span v-if="item.extractPassword">解压: {{ item.extractPassword }}</span>
					<span v-if="item.downloadPassword">下载: {{ item.downloadPassword }}</span>
				</div>
				<div class="tags">
					<Badge v-for="tag in item.tags" :key="tag" :text="tag" />
				</div>
			</div>
		</div>

		<ZRawLink
			v-if="item.link"
			:to="item.link"
			class="download-btn"
			aria-label="下载资源"
			title="下载资源"
			target="_blank"
			rel="noopener"
		>
			<Icon name="tabler:download" />
		</ZRawLink>
		<button
			v-else
			class="download-btn"
			disabled
			aria-label="下载资源"
			title="下载资源"
		>
			<Icon name="tabler:download" />
		</button>
	</li>
</ol>
</template>

<style lang="scss" scoped>
.resource-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1em;

  @media (max-width: 600px) {
    gap: 0.75em;
  }
}

.resource-item {
  display: flex;
  align-items: center;
  gap: 1em;
  padding: 1em;

  @media (max-width: 600px) {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5em;
    padding: 0.75em;
  }
}

.resource-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75em;
  min-width: 0;

  > div {
    display: flex;
    flex-direction: column;
    gap: 0.3em;
  }
}

.resource-title {
  font-weight: 700;
  font-size: 1.05em;
  color: var(--c-text);
}

.resource-subtitle,
.resource-summary {
  margin: 0;
  font-size: 0.9em;
}

.resource-subtitle {
  color: var(--c-text-2);
}

.resource-summary {
  color: var(--c-text-1);
}

.resource-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  font-size: 0.8em;

  @media (max-width: 600px) {
    flex-direction: column;
    align-items: flex-start;
  }
}

.passwords span {
  color: var(--c-text-2);
  background: var(--c-bg-2);
  padding: 0.2em 0.4em;
  border-radius: 0.3em;
}

.passwords,
.tags {
  display: flex;
  flex-wrap: wrap;
}

.passwords {
  gap: 0.5em;
}

.tags {
  gap: 0.25em;
}

.download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.4em;
  height: 2.4em;
  border-radius: 0.5em;
  background: var(--c-primary);
  color: white;
  font-size: 1.1em;
  transition: all 0.2s;

  &:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0.5em 1em var(--ld-shadow);
  }

  &:disabled {
    opacity: 0.5;
  }

  @media (max-width: 600px) {
    width: 2.2em;
    height: 2.2em;
    font-size: 1em;
  }
}
</style>

使用

保存组件并启动开发服务器测试。

tab2

mdc
::resource-list
---
items:
  - id: 1
    title: 示例资源 1
    subtitle: 这是一个副标题
    summary: 这是资源的简短描述
    tags: ["标签1", "标签2"]
    link: "https://example.com/download1"
    extractPassword: "abc123"
    downloadPassword: "def456"
  - id: 2
    title: 示例资源 2
    subtitle: 另一个副标题
    summary: 另一个资源的简短描述
    tags: ["标签3"]
    link: "https://example.com/download2"
---
::

成功渲染如上“组件”所示效果即成功应用。