Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryaang committed Nov 5, 2023
2 parents df941a2 + 87b8162 commit 5fb9b82
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 53 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.1.0](https://github.com/Tim-Saijun/hexo-theme-aurora-s/compare/v1.0.8...v1.1.0) (2023-11-02)


### Features

* loader and proxy configuration message to ([7eb184d](https://github.com/Tim-Saijun/hexo-theme-aurora-s/commit/7eb184da30791abd2e77f10d29357a8d5f135dfc))

## [1.0.8](https://github.com/Tim-Saijun/hexo-theme-aurora-s/compare/v1.0.7...v1.0.8) (2023-11-02)


Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Aurora-s 修改内容与使用方法
点此查看👉[https://www.zair.top/post/hexo-theme-aurora-s](https://www.zair.top/post/hexo-theme-aurora-s)👈
<div align="center">
<a href="https://tridiamond.tech" target="_blank" rel="noopener noreferrer">
<img width="450" alt="image" src="https://user-images.githubusercontent.com/24708758/114228502-196c9000-99a9-11eb-87c7-de981ddc4872.png">
Expand Down
5 changes: 4 additions & 1 deletion layout/index.ejs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><script type="module" crossorigin src="/static/js/58c0bc34.js"></script><link rel="stylesheet" href="/static/css/c538d8c9.css"></head><body id="body-container"><noscript><strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><style>.loader{width:200px;height:22px;border-radius:20px;color:#514b82;border:2px solid;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.loader::before{content:"";position:absolute;margin:2px;inset:0 100% 0 0;border-radius:inherit;background:currentColor;animation:l6 2s infinite}@keyframes l6{100%{inset:0}}</style><script type="module" crossorigin src="/static/js/58c0bc34.js"></script><link rel="stylesheet" href="/static/css/c538d8c9.css"></head><body id="body-container"><noscript><strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div class="loader"><br><br>配置网络代理可以加速访问</div><div id="app"></div><script>window.addEventListener('load', function() {
var loader = document.querySelector('.loader');
loader.remove();
});</script></body></html>
32 changes: 26 additions & 6 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
Categories,
Post,
PostList,
SpecificPostsList,
SpecificPostListRaw,
Tags
} from '@/models/Post.class'
import { Article, Page } from '@/models/Article.class'
import { Statistic } from '@/models/Statistic.class'
import { SearchIndexes } from '@/models/Search.class'
import { paginator } from '@/utils'

// GET /api/site.json
export async function fetchHexoConfig(): Promise<AxiosResponse<any>> {
Expand All @@ -35,16 +36,35 @@ export async function fetchArchivesList(

// GET /api/tags/:TagName.json
export async function fetchPostsListByTag(
tagName: string
tagName: string,
page: number,
pageSize: number
): Promise<AxiosResponse<any>> {
return request.get<SpecificPostsList>(`/tags/${tagName}.json`)
const response = await request.get<SpecificPostListRaw>(
`/tags/${tagName}.json`
)

response.data.postlist = paginator(response.data.postlist, page, pageSize)

return response
}

// GET /api/categories/:slug.json
export async function fetchPostsListByCategory(
categoryName: string
): Promise<AxiosResponse<any>> {
return request.get<SpecificPostsList>(`/categories/${categoryName}.json`)
categoryName: string,
page: number,
pageSize: number
) {
const response = await request.get<SpecificPostListRaw>(
`/categories/${categoryName}.json`
)

response.data.pageSize = pageSize
response.data.total = response.data.postlist.length
response.data.pageCount = Math.ceil(response.data.postlist.length / pageSize)
response.data.postlist = paginator(response.data.postlist, page, pageSize)

return response
}

// GET /api/articles/:Slug.json
Expand Down
10 changes: 5 additions & 5 deletions src/components/Link/LinkCategoryList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<template v-if="links">
<template v-for="category in Object.keys(links)" :key="category">
<MainTitle
:title="convertToLocale(category)"
:title="localizeLink(category)"
:count="links[category].length"
margins="mb-2"
:uppercase="false"
/>
<span class="text-ob-dim mb-8 text-lg">
{{ t(`${convertToLocale(category)}-desc`) }}
{{ t(`${localizeLink(category + '-desc')}`) }}
</span>
<ul :class="linkWrapperClasses(category)">
<template v-for="[i, link] of links[category].entries()" :key="i">
Expand All @@ -17,7 +17,7 @@
:link="link.link"
:avatar="link.avatar"
:description="link.description"
:type="convertToLocale(link.label)"
:type="localizeLink(link.label)"
:vip="link.label === 'links-badge-vip'"
:category-mode="true"
/>
Expand All @@ -32,7 +32,7 @@ import { Link } from '@/models/Article.class'
import { PropType, defineComponent } from 'vue'
import LinkCard from './LinkCard.vue'
import { MainTitle } from '../Title'
import { convertToLocale } from '@/utils'
import { localizeLink } from '@/utils/localization'
import { useI18n } from 'vue-i18n'
export default defineComponent({
Expand All @@ -55,7 +55,7 @@ export default defineComponent({
'xl:grid-cols-4': category === 'links-badge-vip'
}
},
convertToLocale,
localizeLink,
t
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Link/LinkList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:link="link.link"
:avatar="link.avatar"
:description="link.description"
:type="convertToLocale(link.label)"
:type="localizeLink(link.label)"
:vip="link.label === 'links-badge-vip'"
/>
</template>
Expand All @@ -24,7 +24,7 @@
<script lang="ts">
import { Link } from '@/models/Article.class'
import { PropType, defineComponent } from 'vue'
import { convertToLocale } from '@/utils'
import { localizeLink } from '@/utils/localization'
import { SubTitle } from '../Title'
export default defineComponent({
Expand All @@ -38,7 +38,7 @@ export default defineComponent({
}
},
setup() {
return { convertToLocale }
return { localizeLink }
}
})
</script>
25 changes: 17 additions & 8 deletions src/models/Post.class.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { Social } from './ThemeConfig.class'

export interface PostRaw {
[key: string]: Array<any> | string | { [key: string]: any }
}

export interface SpecificPostListRaw {
pageCount: number
pageSize: number
total: number
postlist: PostRaw[]
}

export class NavPost {
title = ''
uid = ''
Expand Down Expand Up @@ -77,9 +88,7 @@ export class Post {
feature = false
pinned = false

constructor(raw?: {
[key: string]: Array<any> | string | { [key: string]: any }
}) {
constructor(raw?: PostRaw) {
if (raw) {
for (const key of Object.keys(this)) {
if (Object.prototype.hasOwnProperty.call(raw, key)) {
Expand Down Expand Up @@ -152,13 +161,13 @@ export class SpecificPostsList {
pageSize = 0
total = 0

constructor(raw?: { [key: string]: [] }) {
constructor(raw?: SpecificPostListRaw) {
if (raw && raw.postlist) {
Object.assign(this, {
data: raw.postlist.map((one: { [key: string]: [] }) => new Post(one)),
pageCount: raw.postlist.length,
pageSize: raw.postlist.length,
total: raw.postlist.length
data: raw.postlist.map(one => new Post(one)),
pageCount: raw.pageCount,
pageSize: raw.pageSize,
total: raw.total
})
}
}
Expand Down
37 changes: 26 additions & 11 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
:pageSize="pagination.pageSize"
:pageTotal="pagination.pageTotal"
:page="pagination.page"
@pageChange="pageChangeHanlder"
@pageChange="pageChangeHandler"
/>
</div>
<div>
Expand Down Expand Up @@ -135,6 +135,7 @@ export default defineComponent({
const categoryStore = useCategoryStore()
const { updateTitleByText } = usePageTitle()
const { t } = useI18n()
const DEFAULT_PAGE_SIZE = 12
/** Variables Section */
Expand All @@ -152,7 +153,7 @@ export default defineComponent({
const activeTab = ref('')
const articleOffset = ref(0)
const pagination = ref({
pageSize: 12,
pageSize: DEFAULT_PAGE_SIZE,
pageTotal: 0,
page: 1
})
Expand Down Expand Up @@ -188,11 +189,7 @@ export default defineComponent({
activeTab.value = slug
backToArticleTop()
if (slug !== '') {
posts.value = new PostList()
postStore.fetchPostsByCategory(slug).then(postList => {
posts.value = postList
pagination.value.pageTotal = postList.total
})
fetchSlugData(slug)
} else {
fetchPostData()
}
Expand All @@ -216,14 +213,32 @@ export default defineComponent({
await postStore.fetchPostsList(pagination.value.page).then(() => {
posts.value = postStore.posts
pagination.value.pageTotal = postStore.posts.total
pagination.value.pageSize = postStore.posts.pageSize
})
}
const pageChangeHanlder = async (page: number) => {
const fetchSlugData = async (slug: string) => {
posts.value = new PostList()
await postStore
.fetchPostsByCategory(
slug,
pagination.value.page,
pagination.value.pageSize
)
.then(postList => {
posts.value = postList
pagination.value.pageTotal = postList.total
})
}
const pageChangeHandler = async (page: number) => {
pagination.value.page = page
backToArticleTop()
await fetchPostData()
if (activeTab.value) {
await fetchSlugData(activeTab.value)
} else {
await fetchPostData()
}
}
return {
Expand Down Expand Up @@ -255,7 +270,7 @@ export default defineComponent({
activeTabStyle,
activeTab,
pagination,
pageChangeHanlder,
pageChangeHandler,
t
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/stores/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,24 @@ export const usePostStore = defineStore({
}, 200)
)
},
async fetchPostsByCategory(category: string): Promise<SpecificPostsList> {
const { data } = await fetchPostsListByCategory(category)
async fetchPostsByCategory(
category: string,
page: number = 1,
pageSize: number = 12
): Promise<SpecificPostsList> {
const { data } = await fetchPostsListByCategory(category, page, pageSize)
return new Promise(resolve =>
setTimeout(() => {
resolve(new SpecificPostsList(data))
}, 200)
)
},
async fetchPostsByTag(slug: string): Promise<SpecificPostsList> {
const { data } = await fetchPostsListByTag(slug)
async fetchPostsByTag(
slug: string,
page: number = 1,
pageSize: number = 12
): Promise<SpecificPostsList> {
const { data } = await fetchPostsListByTag(slug, page, pageSize)
return new Promise(resolve => {
setTimeout(() => {
resolve(new SpecificPostsList(data))
Expand Down
23 changes: 8 additions & 15 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,6 @@ export function getDaysTillNow(from: string) {
return Math.floor(timeDiff / (1000 * 3600 * 24))
}

export function convertToLocale(label: string) {
const locales = [
'links-badge-tech',
'links-badge-designer',
'links-badge-vip',
'links-badge-personal'
]

if (locales.includes(label)) {
return `settings.${label}`
}

return label
}

export function cleanPath(path: string) {
if (path !== '/' && path.at(-1) === '/') {
return path.slice(0, -1)
Expand All @@ -184,3 +169,11 @@ export function throttle(func: () => void, timeFrame: number) {
}
}
}

export function paginator<T>(data: T[], page: number, pageSize: number) {
const skip = pageSize * (page - 1)
// slice function's endIndex will not be included
// therefore the ending index should be pageSize not pageSize - 1
const endIndex = skip > data.length - 1 ? undefined : pageSize * page
return data.slice(skip, endIndex)
}
14 changes: 14 additions & 0 deletions src/utils/localization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const SUPPORTED_LINK_LOCALES = [
'links-badge-tech',
'links-badge-designer',
'links-badge-vip',
'links-badge-personal'
]

export function localizeLink(label: string) {
if (SUPPORTED_LINK_LOCALES.includes(label.replace('-desc', ''))) {
return `settings.${label}`
}

return label.match('-desc') ? '' : label
}

0 comments on commit 5fb9b82

Please sign in to comment.