Skip to content

Commit

Permalink
🐞 fix: mixed content in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Big-Cake-jpg committed Jul 12, 2024
1 parent b6a2265 commit 8fb8acb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions site.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineSiteConfig } from "valaxy";

export default defineSiteConfig({
url: "https://www.lihaoyu.cn",
favicon: "https://blog-api.lihaoyu.cn/favicon",
favicon: "https://blog-api.lihaoyu.cn/images/profile/head.webp",
lang: "zh-CN",
title: "晓雨杂记",
author: {
Expand All @@ -15,7 +15,7 @@ export default defineSiteConfig({
subtitle: "也许我们会分别,但我们将永远不会忘记彼此",

feed: {
favicon: "https://blog-api.lihaoyu.cn/favicon",
favicon: "https://blog-api.lihaoyu.cn/images/profile/head.webp",
},

cdn: {
Expand Down
1 change: 1 addition & 0 deletions valaxy-theme-custom/components/_partial/PostContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const formatDate = (date: string | number | Date) => {
<PostMeta />
<br />
<div class="content break-words">
<TimeWarning />
<div>
<slot />
</div>
Expand Down
40 changes: 40 additions & 0 deletions valaxy-theme-custom/components/_partial/TimeWarning.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script lang="ts" setup>
import { computed, ref, watch } from 'vue'
import { useFrontmatter } from 'valaxy'
import { useI18n } from 'vue-i18n'
import { differenceInMilliseconds, formatDistanceToNow } from 'date-fns'
const fm = useFrontmatter()
const { t, locale } = useI18n()
const updated = computed(() => fm.value.updated || fm.value.date || new Date())
const ago = ref('')
watch(locale, () => {
const fromNow = formatDistanceToNow(updated.value, { addSuffix: true })
ago.value = /^\d/.test(fromNow) ? ` ${fromNow}` : fromNow
}, { immediate: true })
/**
* when the post is updated more than 180 days ago, show a warning
* default 180 days, you can set `time_warning` in frontmatter to change it
*/
const time_warning = computed(() => {
const diff = differenceInMilliseconds(new Date(), updated.value)
/**
* if `time_warning` is a number, compare the time difference
* if `time_warning` is a boolean, show warning by flag
*/
if (typeof fm.value.time_warning === 'number')
return diff > fm.value.time_warning
else
return fm.value.time_warning
})
</script>

<template>
<blockquote v-if="time_warning" op="80">
{{ t('post.time_warning', { ago }) }}
</blockquote>
</template>

0 comments on commit 8fb8acb

Please sign in to comment.