Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

archive归档调整 #674

Merged
merged 1 commit into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions pages/archive/index.js
Expand Up @@ -25,6 +25,27 @@ export async function getStaticProps() {
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
delete props.allPages

const postsSortByDate = Object.create(props.posts)

postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date?.slice(0, 7) || post.createdTime
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})

props.archivePosts = archivePosts

return {
props,
revalidate: BLOG.NEXT_REVALIDATE_SECOND
Expand Down
19 changes: 1 addition & 18 deletions themes/example/LayoutArchive.js
Expand Up @@ -3,25 +3,8 @@ import Link from 'next/link'
import LayoutBase from './LayoutBase'

export const LayoutArchive = props => {
const { posts } = props
const postsSortByDate = Object.create(posts)
const { archivePosts } = props

postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
return (
<LayoutBase {...props}>
<div className="mb-10 pb-20 md:py-12 p-3 min-h-screen w-full">
Expand Down
21 changes: 1 addition & 20 deletions themes/fukasawa/LayoutArchive.js
Expand Up @@ -3,26 +3,7 @@ import BlogArchiveItem from './components/BlogPostArchive'
import LayoutBase from './LayoutBase'

export const LayoutArchive = (props) => {
const { posts } = props
// 深拷贝
const postsSortByDate = Object.create(posts)

// 时间排序
postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})
const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
const { archivePosts } = props

useEffect(() => {
const anchor = window.location.hash
Expand Down
22 changes: 1 addition & 21 deletions themes/hexo/LayoutArchive.js
Expand Up @@ -4,27 +4,7 @@ import Card from './components/Card'
import LayoutBase from './LayoutBase'

export const LayoutArchive = (props) => {
const { posts } = props
// 深拷贝
const postsSortByDate = Object.create(posts)

// 时间排序
postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
const { archivePosts } = props

useEffect(() => {
const anchor = window.location.hash
Expand Down
22 changes: 1 addition & 21 deletions themes/matery/LayoutArchive.js
Expand Up @@ -4,27 +4,7 @@ import Card from './components/Card'
import LayoutBase from './LayoutBase'

export const LayoutArchive = (props) => {
const { posts } = props
// 深拷贝
const postsSortByDate = Object.create(posts)

// 时间排序
postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
const { archivePosts } = props

useEffect(() => {
const anchor = window.location.hash
Expand Down
21 changes: 2 additions & 19 deletions themes/medium/LayoutArchive.js
Expand Up @@ -3,25 +3,8 @@ import Link from 'next/link'
import LayoutBase from './LayoutBase'

export const LayoutArchive = props => {
const { posts } = props
const postsSortByDate = Object.create(posts)
const { archivePosts } = props

postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
return (
<LayoutBase {...props}>
<div className="mb-10 pb-20 md:py-12 py-3 min-h-full">
Expand Down Expand Up @@ -60,5 +43,5 @@ export const LayoutArchive = props => {
))}
</div>
</LayoutBase>
);
)
}
22 changes: 1 addition & 21 deletions themes/next/LayoutArchive.js
Expand Up @@ -3,27 +3,7 @@ import LayoutBase from './LayoutBase'
import BlogPostArchive from './components/BlogPostArchive'

export const LayoutArchive = (props) => {
const { posts } = props
// 深拷贝
const postsSortByDate = Object.create(posts)

// 时间排序
postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
const { archivePosts } = props

useEffect(() => {
const anchor = window.location.hash
Expand Down
21 changes: 2 additions & 19 deletions themes/nobelium/LayoutArchive.js
Expand Up @@ -3,25 +3,8 @@ import Link from 'next/link'
import LayoutBase from './LayoutBase'

export const LayoutArchive = props => {
const { posts } = props
const postsSortByDate = Object.create(posts)
const { archivePosts } = props

postsSortByDate.sort((a, b) => {
const dateA = new Date(a?.date?.start_date || a.createdTime)
const dateB = new Date(b?.date?.start_date || b.createdTime)
return dateB - dateA
})

const archivePosts = {}

postsSortByDate.forEach(post => {
const date = post.date?.start_date.slice(0, 7)
if (archivePosts[date]) {
archivePosts[date].push(post)
} else {
archivePosts[date] = [post]
}
})
return (
<LayoutBase {...props}>
<div className="mb-10 pb-20 md:py-12 p-3 min-h-screen w-full">
Expand Down Expand Up @@ -58,5 +41,5 @@ export const LayoutArchive = props => {
))}
</div>
</LayoutBase>
);
)
}