Skip to content

Commit

Permalink
Merge pull request #335 from XPoet/dev
Browse files Browse the repository at this point in the history
Release new version
  • Loading branch information
XPoet authored Jul 5, 2024
2 parents 4ebe932 + 27ef552 commit 0fa5b27
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ body:
I made sure I checked
我确认我已经检查过了
options:
- label: I am using Keep version `4.1.4` or later. (使用 Keep `4.1.4` 或更高版本)
- label: I am using Keep version `4.1.5` or later. (使用 Keep `4.1.5` 或更高版本)
required: true
- label: I have already read the [Troubleshooting page of Hexo](https://hexo.io/docs/troubleshooting) and [Keep documents](https://keep-docs.xpoet.cn). (已阅读 [Hexo 故障处理页面](https://hexo.io/docs/troubleshooting) 和 [Keep 文档](https://keep-docs.xpoet.cn))
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ body:
I made sure I checked
我确认我已经检查过了
options:
- label: I am using Keep version `4.1.4` or later. (使用 Keep `4.1.4` 或更高版本)
- label: I am using Keep version `4.1.5` or later. (使用 Keep `4.1.5` 或更高版本)
required: true
- label: I have already read the [Troubleshooting page of Hexo](https://hexo.io/docs/troubleshooting) and [Keep documents](https://keep-docs.xpoet.cn). (已阅读 [Hexo 故障处理页面](https://hexo.io/docs/troubleshooting) 和 [Keep 文档](https://keep-docs.xpoet.cn))
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/other.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ body:
I made sure I checked
我确认我已经检查过了
options:
- label: I am using Keep version `4.1.4` or later. (使用 Keep `4.1.4` 或更高版本)
- label: I am using Keep version `4.1.5` or later. (使用 Keep `4.1.5` 或更高版本)
required: true
- label: I have already read the [Troubleshooting page of Hexo](https://hexo.io/docs/troubleshooting) and [Keep documents](https://keep-docs.xpoet.cn). (已阅读 [Hexo 故障处理页面](https://hexo.io/docs/troubleshooting) 和 [Keep 文档](https://keep-docs.xpoet.cn))
required: true
Expand Down
3 changes: 2 additions & 1 deletion languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ comment:
page_not_found: Page Not Found
go_home: Take me home
encryption:
excerpt: 🔒 The post has been encrypted, please enter the password to view it.
excerpt: 🔒 The post has been encrypted and can only be viewed after entering the password.
input_password: Please enter password ...
re_encryption: Re-encryption
3 changes: 2 additions & 1 deletion languages/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ comment:
page_not_found: 页面找不到
go_home: 前往首页
encryption:
excerpt: 🔒 文章已加密,请在输入密码后查看
excerpt: 🔒 文章已加密,输入密码后才能查看
input_password: 请输入密码...
re_encryption: 重新加密
3 changes: 2 additions & 1 deletion languages/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ comment:
page_not_found: 頁面缺失
go_home: 前往首頁
encryption:
excerpt: 🔒 文章已加密,請在輸入密碼後查看
excerpt: 🔒 文章已加密,輸入密碼後才能查看
input_password: 請輸入密碼...
re_encryption: 重新加密
4 changes: 3 additions & 1 deletion layout/_partial/post/post-tools.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<ul class="post-tools-list border-box">
<!-- PC encrypt again -->
<% if (page?.password) { %>
<li class="tools-item flex-center post-lock">
<li class="status-item flex-center post-lock border-box"
data-tooltip-content="<%= __('encryption.re_encryption') %>"
>
<i class="fa-solid fa-lock"></i>
<i class="fa-solid fa-lock-open"></i>
</li>
Expand Down
6 changes: 6 additions & 0 deletions layout/_partial/scripts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<% } %>
<div class="<%= theme?.pjax?.enable === true ? 'pjax' : '' %>">
<!-- home page -->
<% if (is_home()) { %>
<%- __js('js/page/home-page.js') %>
<% } %>
<!-- post page -->
<% if (is_post()) { %>
<!-- post-helper -->
<%- __js('js/post/post-helper.js') %>
Expand Down
6 changes: 5 additions & 1 deletion source/css/layout/_page/post.styl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ $spacer-padding = 2rem
padding 1rem 0

.password-input {
width 20rem
width 60%
margin 0
padding 0.8rem 1.2rem
color var(--text-color-3)
Expand All @@ -290,6 +290,10 @@ $spacer-padding = 2rem
border-bottom 0.2rem solid var(--border-color)
outline none

+keep-tablet() {
width 80%
}

&.error {
border 0.2rem solid var(--keep-danger-color)
}
Expand Down
30 changes: 19 additions & 11 deletions source/css/layout/_partial/post/post-tools.styl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ $post-tool-button-width = 2.5rem
padding-top var(--component-gap)

.post-tools-list {

li {
margin-bottom $li-margin-bottom

&:last-child {
margin-bottom 0
}
}


li.tools-item {
position relative
box-sizing border-box
width $post-tool-button-width
height $post-tool-button-width
margin-bottom $li-margin-bottom
color var(--text-color-3)
font-size 1.2rem
background var(--background-color-1)
Expand All @@ -38,11 +45,6 @@ $post-tool-button-width = 2.5rem
}


&:last-child {
margin-bottom 0
}


&.toggle-show-toc {
display none
}
Expand Down Expand Up @@ -70,6 +72,16 @@ $post-tool-button-width = 2.5rem
}
}
}
}


li.status-item {
width $post-tool-button-width
height $post-tool-button-width
color var(--text-color-3)
font-size 1.6rem
cursor pointer


&.post-lock {
cursor default
Expand All @@ -79,10 +91,6 @@ $post-tool-button-width = 2.5rem
color var(--keep-success-color)
}

.fa-lock {
color var(--keep-warning-color)
}

&.decrypt {
cursor pointer

Expand Down
3 changes: 2 additions & 1 deletion source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ window.addEventListener('DOMContentLoaded', () => {
isDark: false,
fontSizeLevel: 0,
isShowToc: true
}
},
defaultDatetimeFormat: 'YYYY-MM-DD HH:mm:ss'
}

// print theme base info
Expand Down
102 changes: 102 additions & 0 deletions source/js/page/home-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* global KEEP */

function homePageHandler() {
const { post_datetime, post_datetime_format, announcement } = KEEP.theme_config?.home || {}
const fsc = KEEP.theme_config?.first_screen || {}

// reset home post update datetime
const resetHomePostUpdateDate = () => {
if (post_datetime === 'updated' && post_datetime_format) {
const datetimeDoms = document.querySelectorAll('.post-meta-info .home-post-history')
datetimeDoms.forEach((datetimeDom) => {
const updated = new Date(datetimeDom.dataset.updated).getTime()
const format = post_datetime_format || KEEP.themeInfo.defaultDatetimeFormat
datetimeDom.innerHTML = KEEP.utils.formatDatetime(format, updated)
})
}
}

// set how long age in home post block
const setHowLongAgoInHome = () => {
if (post_datetime_format && post_datetime_format !== 'ago') {
return
}
const datetimeDoms = document.querySelectorAll('.post-meta-info .home-post-history')
datetimeDoms.forEach((v) => {
const nowTimestamp = Date.now()
const updatedTimestamp = new Date(v.dataset.updated).getTime()
v.innerHTML = KEEP.utils.getHowLongAgo(Math.floor((nowTimestamp - updatedTimestamp) / 1000))
})
}

// close website announcement
const closeWebsiteAnnouncement = () => {
if (announcement) {
const waDom = document.querySelector('.home-content-container .website-announcement')
if (waDom) {
const closeDom = waDom.querySelector('.close')
closeDom.addEventListener('click', () => {
waDom.style.display = 'none'
})
}
}
}

// first screen typewriter
const initTypewriter = () => {
const isHitokoto = fsc?.hitokoto === true

if (fsc?.enable !== true) {
return
}

if (fsc?.enable === true && !isHitokoto && !fsc?.description) {
return
}

const descBox = document.querySelector('.first-screen-content .description')
if (descBox) {
descBox.style.opacity = '0'

setTimeout(
() => {
descBox.style.opacity = '1'
const descItemList = descBox.querySelectorAll('.desc-item')
descItemList.forEach((descItem) => {
const desc = descItem.querySelector('.desc')
const cursor = descItem.querySelector('.cursor')
const text = desc.innerHTML
desc.innerHTML = ''
let charIndex = 0

if (text) {
const typewriter = () => {
if (charIndex < text.length) {
desc.textContent += text.charAt(charIndex)
charIndex++
setTimeout(typewriter, 100)
} else {
cursor.style.display = 'none'
}
}

typewriter()
}
})
},
isHitokoto ? 400 : 300
)
}
}

resetHomePostUpdateDate()
setHowLongAgoInHome()
closeWebsiteAnnouncement()
initTypewriter()
}

if (KEEP.theme_config?.pjax?.enable === true && KEEP.utils) {
homePageHandler()
} else {
window.addEventListener('DOMContentLoaded', homePageHandler)
}
50 changes: 15 additions & 35 deletions source/js/post/post-helper.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/* global KEEP */

async function initPostHelper() {
const encryptClassName = 'encrypt'

KEEP.utils.postHelper = {
postPageContainerDom: document.querySelector('.post-page-container'),
toggleShowTocBtn: document.querySelector('.toggle-show-toc'),
toggleShowTocTabletBtn: document.querySelector('.toggle-show-toc-tablet'),
mainContentDom: document.querySelector('.main-content'),
postToolsDom: document.querySelector('.post-tools'),

isShowToc: false,

initToggleToc() {
this.toggleShowTocBtn &&
this.toggleShowTocBtn.addEventListener('click', () => {
if (this.postPageContainerDom.classList.contains(encryptClassName)) {
return
}
this.isShowToc = !this.isShowToc
KEEP.themeInfo.styleStatus.isShowToc = this.isShowToc
KEEP.setStyleStatus()
Expand All @@ -21,6 +25,10 @@ async function initPostHelper() {

this.toggleShowTocTabletBtn &&
this.toggleShowTocTabletBtn.addEventListener('click', () => {
if (this.postPageContainerDom.classList.contains(encryptClassName)) {
return
}

const tabletTocMask = document.querySelector('.tablet-post-toc-mask')
const tabletToc = tabletTocMask.querySelector('.tablet-post-toc')

Expand Down Expand Up @@ -143,43 +151,14 @@ async function initPostHelper() {
}
},

formatDatetime(fmt = 'YYYY-MM-DD hh:mm:ss', timestamp = Date.now()) {
function padLeftZero(str) {
return `00${str}`.substr(str.length)
}

const date = new Date(timestamp)

if (/(y+)/.test(fmt) || /(Y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, `${date.getFullYear()}`.substr(4 - RegExp.$1.length))
}

const obj = {
'M+': date.getMonth() + 1,
'D+': date.getDate(),
'd+': date.getDate(),
'H+': date.getHours(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
}

for (const key in obj) {
if (new RegExp(`(${key})`).test(fmt)) {
const str = `${obj[key]}`
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : padLeftZero(str))
}
}
return fmt
},

// reset post update datetime
resetPostUpdateDate() {
const updateDateDom = document.querySelector(
'.post-meta-info-container .post-update-date .datetime'
)
const updated = new Date(updateDateDom.dataset.updated).getTime()
const format = KEEP.theme_config.post?.datetime_format || 'YYYY-MM-DD HH:mm:ss'
updateDateDom.innerHTML = this.formatDatetime(format, updated)
const format = KEEP.theme_config.post?.datetime_format || KEEP.themeInfo.defaultDatetimeFormat
updateDateDom.innerHTML = KEEP.utils.formatDatetime(format, updated)
},

// enable full screen
Expand Down Expand Up @@ -301,7 +280,7 @@ async function initPostHelper() {
const dc = await this.decrypt({ iv, encryptedData: content }, secret)
encryptBoxDom.style.display = 'none'
postContentDom.removeChild(encryptBoxDom)
this.postPageContainerDom.classList.remove('encrypt')
this.postPageContainerDom.classList.remove(encryptClassName)
this.encryptTocHandle(true)
postContentDom.querySelector('.post').innerHTML = dc
setTimeout(() => {
Expand All @@ -315,6 +294,7 @@ async function initPostHelper() {
KEEP.utils.aAnchorJump()
})
lockIconDom.classList.add(lockClassName)
lockIconDom.classList.add('tooltip')
sessionStorage.setItem(`${KEEP.themeInfo.encryptKey}#${location.pathname}`, '1')
}

Expand Down Expand Up @@ -369,7 +349,7 @@ async function initPostHelper() {
KEEP.utils.postHelper.resetPostUpdateDate()
KEEP.utils.postHelper.enableFullScreen()

if (KEEP.utils.postHelper.postPageContainerDom.classList.contains('encrypt')) {
if (KEEP.utils.postHelper.postPageContainerDom.classList.contains(encryptClassName)) {
await KEEP.utils.postHelper.postEncryptHandle()
}

Expand Down
Loading

0 comments on commit 0fa5b27

Please sign in to comment.