[feat] author

This commit is contained in:
xaoxuu 2024-01-04 22:50:57 +08:00
parent 5d7f131c0e
commit 3b300104af
16 changed files with 203 additions and 56 deletions

View File

@ -24,6 +24,7 @@ meta:
comment_title: Join the discussion comment_title: Join the discussion
back_to_top: Back to top back_to_top: Back to top
more: 'More %s' more: 'More %s'
created_author: '%s posted on'
created: 'Posted on' created: 'Posted on'
updated: 'Updated on' updated: 'Updated on'
license: License license: License

View File

@ -24,6 +24,7 @@ meta:
comment_title: 快来参与讨论吧 comment_title: 快来参与讨论吧
back_to_top: 回到顶部 back_to_top: 回到顶部
more: '更多「%s」' more: '更多「%s」'
created_author: 本文由 %s 发布于
created: 发布于 created: 发布于
updated: 更新于 updated: 更新于
license: 许可协议 license: 许可协议

View File

@ -24,6 +24,7 @@ meta:
comment_title: 參與討論 comment_title: 參與討論
back_to_top: 回到頁首 back_to_top: 回到頁首
more: '更多「%s」' more: '更多「%s」'
created_author: 本文由 %s 發布於
created: 發布於 created: 發布於
updated: 更新於 updated: 更新於
license: 授權條款 license: 授權條款

View File

@ -0,0 +1,31 @@
<%
function layoutDiv() {
const author = page.author
var el = ``
el += `<div class="tag-plugin banner author">`
if (author.banner) {
el += `<img class="bg" src="${author.banner}">`
}
el += `
<div class="content">
<div class="top">
<button class="back cap" onclick="window.history.back()">
<svg aria-hidden="true" viewBox="0 0 16 16" fill="currentColor">
<path fill-rule="evenodd" d="M7.78 12.53a.75.75 0 01-1.06 0L2.47 8.28a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 1.06L4.81 7h7.44a.75.75 0 010 1.5H4.81l2.97 2.97a.75.75 0 010 1.06z"></path>
</svg>
</button>
</div>
<div class="bottom">
<img class="avatar" src="${author.avatar}">
<div class="text-area">
<p class="text title">${author.name}</p>
<div class="text subtitle">${author.description || ""}</div>
</div>
</div>
</div>
`
el += `</div>`
return el
}
%>
<%- layoutDiv() %>

View File

@ -35,13 +35,29 @@ function layoutDiv() {
}); });
} }
el += '</div>'; el += '</div>';
// 发布日期 // 作者
var author = null
if (theme.authors) {
if (page.author?.length > 0 && theme.authors[page.author] != null) {
author = theme.authors[page.author]
} else {
author = theme.default_author
}
}
el += '<div id="post-meta">'; el += '<div id="post-meta">';
if (author) {
let link = `<a href="${url_for(author.path)}">${author.name}</a>`
el += `<span class="author">${__("meta.created_author", link)}</span>`
} else {
el += `<span class="author">${__("meta.created")}</span>`
}
// 发布日期
el += ` el += `
<span>${__("meta.created")}&nbsp;<time datetime="${date_xml(page.date)}">${date(page.date, config.date_format)}</time></span> <span class="created"><time datetime="${date_xml(page.date)}">${date(page.date, config.date_format)}</time></span>
`; `;
// 更新日期
el += ` el += `
<span>${__("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span> <span class="updated">${__("symbol.comma") + __("meta.updated")}&nbsp;<time datetime="${date_xml(page.updated)}">${date(page.updated, config.date_format)}</time></span>
`; `;
el += '</div>'; el += '</div>';

View File

@ -68,8 +68,20 @@ function div_default() {
// meta // meta
el += '<div class="meta cap">'; el += '<div class="meta cap">';
// time
el += '<span class="cap" id="post-meta">'; el += '<span class="cap" id="post-meta">';
// author
var author = null
if (theme.authors) {
if (page.author?.length > 0 && theme.authors[page.author] != null) {
author = theme.authors[page.author]
} else {
author = theme.default_author
}
}
if (author) {
el += author.name + '&nbsp;'
}
// time
el += __("meta.created") + '&nbsp;' + '<time datetime="' + date_xml(post.date) + '">' + date(post.date, config.date_format) + '</time>'; el += __("meta.created") + '&nbsp;' + '<time datetime="' + date_xml(post.date) + '">' + date(post.date, config.date_format) + '</time>';
el += '</span>'; el += '</span>';
// cat // cat

View File

@ -3,41 +3,58 @@ page.robots = 'noindex,follow';
if (page.menu_id == undefined) { if (page.menu_id == undefined) {
page.menu_id = 'post'; page.menu_id = 'post';
} }
if (page.author) {
page.header = 'auto';
}
function layoutArchiveList() {
var el = ''
if (page.author) {
page.title = page.author.name
el += partial('_partial/main/navbar/author_banner')
} else {
page.title = __('btn.archives')
el += partial('_partial/main/navbar/list_post')
}
el += `<div class="post-list archives">`
var years = []
site.posts.sort('date', -1).each(function(post) {
post.year = date(post.date, 'YYYY')
if (post.year && (years.includes(post.year) == false) && (post.title || post.date)) {
years.push(post.year)
}
})
for (let year of years) {
el += `<article class="${scrollreveal()}" id="archive">`
el += `<div class='archive-header h4'>${year}</div>`
site.posts.sort('date', -1).filter(function (post) {
post.year = date(post.date, 'YYYY')
return post.year == year
}).each(function(post) {
el += `<div class="archive-list">`
el +=`<a class='post fs14' href="${url_for(post.link || post.path)}">`
el += `<time>${date(post.date, 'MM-DD')}</time>`
el += `<span>`
if (post.title) {
el += post.title
} else if (post.date) {
el += date(post.date, config.date_format)
}
el += `</span>`
el += `</a>`
el += `</div>`
})
el += `</article>`
}
el += `</div>`
return el
}
function layoutDiv() {
if (page.posts && (is_category() || is_tag())) {
return partial('index')
} else {
return layoutArchiveList()
}
}
%> %>
<% if (page.posts && (is_category() || is_tag())) { %>
<%- partial('index') %> <%- layoutDiv() %>
<% } else { %>
<% page.title = __('btn.archives'); %>
<%- partial('_partial/main/navbar/list_post') %>
<div class='post-list'>
<% var years = []; %>
<% site.posts.sort('date', -1).each(function(post) { %>
<% post.year = date(post.date, 'YYYY'); %>
<% if (post.year && (years.includes(post.year) == false) && (post.title || post.date)) { %>
<% years.push(post.year); %>
<% } %>
<% }); %>
<% years.forEach((year, i) => { %>
<article class='<%- scrollreveal() %>' id='archive'>
<div class='archive-header h4'><%= year %></div>
<% site.posts.sort('date', -1).filter(function (post) { %>
<% post.year = date(post.date, 'YYYY'); %>
<% return post.year == year; %>
<% }).each(function(post) { %>
<div class='archive-list'>
<a class='post fs14' href="<%= url_for(post.link || post.path) %>">
<time><%= date(post.date, 'MM-DD') %></time>
<span>
<% if (post.title) { %>
<%- post.title %>
<% } else if (post.date) { %>
<%= date(post.date, config.date_format) %>
<% } %>
</span>
</a>
</div>
<% }); %>
</article>
<% }); %>
</div>
<% } %>

View File

@ -6,6 +6,7 @@ hexo.on('generateBefore', () => {
// Merge config. // Merge config.
require('./lib/config')(hexo); require('./lib/config')(hexo);
require('./lib/links')(hexo); require('./lib/links')(hexo);
require('./lib/authors')(hexo);
require('./lib/doc_tree')(hexo); require('./lib/doc_tree')(hexo);
require('./lib/utils')(hexo); require('./lib/utils')(hexo);
}); });

View File

@ -0,0 +1,21 @@
/**
* authors.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/
*/
'use strict';
module.exports = ctx => {
var authors = ctx.locals.get('data').authors || {}
let basePath = ctx.config.author_dir || 'author'
// url
for (let key of Object.keys(authors)) {
let author = authors[key]
author.path = `${basePath}/${key}/index.html`
}
// default author
const keys = Object.keys(authors)
if (keys.length > 0) {
ctx.theme.config.default_author = authors[keys[0]]
}
ctx.theme.config.authors = authors
}

View File

@ -1,5 +1,5 @@
/** /**
* doc_tree.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/ * links.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/
*/ */
'use strict'; 'use strict';

View File

@ -0,0 +1,22 @@
/**
* author v1 | https://github.com/xaoxuu/hexo-theme-stellar/
*/
hexo.extend.generator.register('author', function (locals) {
const { authors } = hexo.theme.config
var pages = []
for (let key of Object.keys(authors)) {
const author = authors[key]
if (author.hidden) {
continue
}
pages.push({
path: author.path,
layout: ['archive'],
data: {
'author': author
}
})
}
return pages
});

View File

@ -170,4 +170,8 @@
p:last-child p:last-child
margin-bottom: 0 margin-bottom: 0
.cap+.cap .cap+.cap
margin-left: 4px margin-left: 4px
.post-list.archives
@media screen and (max-width: $device-mobile)
margin: 1rem 0

View File

@ -12,3 +12,7 @@
margin: 2rem 1rem 1rem margin: 2rem 1rem 1rem
.logo-wrap .logo-wrap
margin: 0 margin: 0
.l_main.list
@media screen and (max-width: $device-mobile-max)
padding-top: 0

View File

@ -24,14 +24,18 @@
align-items: baseline align-items: baseline
margin: 0.25rem 0 margin: 0.25rem 0
color: var(--text-p1) color: var(--text-p1)
&:hover trans2 color border
color: $color-hover border-bottom: 1px dashed var(--text-meta)
time time
font-family: $ff-code font-family: $ff-code
margin-right: 1em margin-right: 1em
font-weight: 700 font-weight: 700
flex-shrink: 0 flex-shrink: 0
opacity .5 color: var(--text-p4)
&:hover
border-bottom: 1px solid $color-theme
time
color: $color-theme
&:hover &:hover
.archive-header .archive-header
color: var(--text-p1) color: var(--text-p1)

View File

@ -19,13 +19,11 @@
color: $color-hover color: $color-hover
div#post-meta div#post-meta
margin-top: 2px margin-top: 2px
span+span span.updated
margin-left: 8px
visibility: hidden visibility: hidden
&:hover &:hover
div#post-meta div#post-meta span.updated
span+span visibility: visible
visibility: visible
.bread-nav .ghrepo .bread-nav .ghrepo
font-size: $fs-13 font-size: $fs-13

View File

@ -6,7 +6,6 @@
flex-direction: column flex-direction: column
justify-content: flex-end justify-content: flex-end
align-items: flex-start align-items: flex-start
color: white
height: 240px height: 240px
@media screen and (max-width: $device-mobile-max) @media screen and (max-width: $device-mobile-max)
height: 200px height: 200px
@ -78,14 +77,11 @@
border-radius: 50% border-radius: 50%
width: 48px width: 48px
height: 48px height: 48px
border: 2px solid white
.bottom .bottom
display: flex display: flex
padding: 1rem padding: 1rem
width: 100% width: 100%
box-sizing: border-box box-sizing: border-box
background-image: linear-gradient(rgba(0,0,0,0),rgba(0,0,0,0.2))
text-shadow: 0 0 1px rgba(0,0,0,0.12)
.title .title
font-size: 1.5rem font-size: 1.5rem
font-weight: 600 font-weight: 600
@ -99,9 +95,27 @@
font-size: 1.2rem font-size: 1.2rem
.subtitle .subtitle
font-size: $fs-14 font-size: $fs-14
.content:only-child
color: var(--text-p1)
.bg+.content
color: white
.avatar
border: 2px solid white
.bottom
background-image: linear-gradient(rgba(0,0,0,0),rgba(0,0,0,0.2))
text-shadow: 0 0 1px rgba(0,0,0,0.12)
.tag-plugin.banner .tag-plugin.banner
trans1(transform, 2s) trans1(transform, 2s)
&:hover &:hover
img.bg img.bg
transform: scale(1.01) transform: scale(1.01)
.l_main.list .tag-plugin.banner
background: var(--block-hover)
.content .top
margin-top: 1.5rem
margin: 0 1rem
@media screen and (max-width: $device-mobile)
margin: 0
border-radius: 0