From 4c0d15b255d6953626125f82ba149a36f4d36cb0 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Tue, 14 Jan 2025 03:00:07 +0800 Subject: [PATCH] change recent activity style --- components/card/GitCard.vue | 85 +++++++++++++++++++++++-------------- pages/index.vue | 28 ++++-------- plugins/fontawsome.ts | 3 +- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/components/card/GitCard.vue b/components/card/GitCard.vue index 9248d12..ce2e5ac 100644 --- a/components/card/GitCard.vue +++ b/components/card/GitCard.vue @@ -2,15 +2,19 @@ import { computed } from 'vue' const props = defineProps<{ - commit: IActivity + commit: IStrictActivity }>(), + commit_ref_name = computed(() => props.commit.ref_name.substring(props.commit.ref_name.lastIndexOf('/') + 1)), + icon = computed(() => { switch (props.commit.op_type) { case 'merge_pull_request': return ['fas', 'code-merge'] case 'create_repo': - return ['fab', 'git-alt'] + return ['fas', 'book-medical'] + case 'delete_branch': + case 'delete_tag': case 'commit_repo': default: return ['fas', 'code-commit'] @@ -46,47 +50,62 @@ const props = defineProps<{ return `${years} 年前` }, - - handleClick = () => { - window.open(props.commit.repo.html_url, '_self') - } + calcHeight = (n: number) => `${n * 2.5}rem` diff --git a/pages/index.vue b/pages/index.vue index 952a71d..74fffd3 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -22,7 +22,6 @@ const { $mitt } = useNuxtApp(), git: undefined, }), - config = useRuntimeConfig(), getBlogRecentPost = get, unknown>('/blog/index.php/api/posts', { params: { showDigest: 'excerpt', @@ -30,11 +29,9 @@ const { $mitt } = useNuxtApp(), }, }), getActivity = get('/git/api/v1/users/cantyonion/activities/feeds', { - headers: { - Authorization: ` ${config.public.gitApiKey}`, - }, params: { - limit: 10, + 'limit': 10, + 'only-performed-by': true, }, }), @@ -49,25 +46,16 @@ const { $mitt } = useNuxtApp(), } return recentPosts.value }), - activitiesData = computed((): IActivity[] => { + activitiesData = computed((): IStrictActivity[] => { if (!Array.isArray(recentActivities.value)) { return [] } return recentActivities.value.map((item) => { - try { - if (item.op_type === 'commit_repo') { - return { - ...item, - content: JSON.parse(item.content), - } - } - return null + return { + ...item, + content: typeof item.content === 'string' && item.content ? JSON.parse(item.content) : null, } - catch (e) { - console.error(e) - return null - } - }).filter(item => item !== null) + }) }), reloadPosts = async () => { @@ -158,7 +146,7 @@ onMounted(() => { @reload="reloadActivities" >