Skip to content

Commit

Permalink
Merge pull request #30 from expoli/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
expoli authored Apr 6, 2023
2 parents 50522d3 + 1adcccd commit 28e7ef8
Show file tree
Hide file tree
Showing 21 changed files with 321 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables
NEXT_PUBLIC_VERSION=3.13.2
NEXT_PUBLIC_VERSION=3.13.3
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

<td align="center"><a href="https://github.com/fighting-bug"><img src="https://avatars.githubusercontent.com/u/56441589" width="64px;" alt="fighting-buf"/><br/><sub><b>fighting-buf</b></sub></a><br/><a href="https://github.com/tangly1024/NotionNext/commits?author=fighting-bug" title="fighting-buf" >🔧 🐛</a></td>

<td align="center"><a href="https://github.com/cliouo"><img src="https://avatars.githubusercontent.com/u/71540889" width="64px;" alt="cliouo"/><br/><sub><b>cliouo</b></sub></a><br/><a href="https://github.com/tangly1024/NotionNext/commits?author=cliouo" title="cliouo" >🔧 🐛</a></td>

</tr>
</table>
Expand Down
17 changes: 16 additions & 1 deletion blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const BLOG = {
MUSIC_PLAYER: process.env.NEXT_PUBLIC_MUSIC_PLAYER || true, // 是否使用音乐播放插件
MUSIC_PLAYER_VISIBLE: process.env.NEXT_PUBLIC_MUSIC_PLAYER_VISIBLE || true, // 是否在左下角显示播放和切换,如果使用播放器,打开自动播放再隐藏,就会以类似背景音乐的方式播放,无法取消和暂停
MUSIC_PLAYER_AUTO_PLAY: process.env.NEXT_PUBLIC_MUSIC_PLAYER_AUTO_PLAY || false, // 是否自动播放,不过自动播放时常不生效(移动设备不支持自动播放)
MUSIC_PLAYER_SHOW_LRC: process.env.NEXT_PUBLIC_MUSIC_PLAYER_SHOW_LRC || false, // 是否展示歌词(前提是有配置歌词路径,对 meting 无效)
MUSIC_PLAYER_LRC_TYPE: process.env.NEXT_PUBLIC_MUSIC_PLAYER_LRC_TYPE || '0', // 歌词显示类型,可选值: 3 | 1 | 0(0:禁用 lrc 歌词,1:lrc 格式的字符串,3:lrc 文件 url)(前提是有配置歌词路径,对 meting 无效)
MUSIC_PLAYER_CDN_URL: process.env.NEXT_PUBLIC_MUSIC_PLAYER_CDN_URL || 'https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/aplayer/1.10.1/APlayer.min.js',
MUSIC_PLAYER_ORDER: process.env.NEXT_PUBLIC_MUSIC_PLAYER_ORDER || 'list', // 默认播放方式,顺序 list,随机 random
MUSIC_PLAYER_AUDIO_LIST: [ // 示例音乐列表。除了以下配置外,还可配置歌词,具体配置项看此文档 https://aplayer.js.org/#/zh-Hans/
Expand Down Expand Up @@ -179,6 +179,21 @@ const BLOG = {
COMMENT_WALINE_SERVER_URL: process.env.NEXT_PUBLIC_WALINE_SERVER_URL || '', // 请配置完整的Waline评论地址 例如 hhttps://preview-waline.tangly1024.com @see https://waline.js.org/guide/get-started.html
COMMENT_WALINE_RECENT: process.env.NEXT_PUBLIC_WALINE_RECENT || false, // 最新评论

// 此评论系统基于WebMention,细节可参考https://webmention.io
// 它是一个基于IndieWeb理念的开放式评论系统,下方COMMENT_WEBMENTION包含的属性皆需配置:
// ENABLE: 是否开启
// AUTH: Webmention使用的IndieLogin,可使用Twitter或Github个人页面连结
// HOSTNAME: Webmention绑定之网域,通常即为本站网址
// TWITTER_USERNAME: 评论显示区域需要的资讯
// TOKEN: Webmention的API token
COMMENT_WEBMENTION: {
ENABLE: process.env.NEXT_PUBLIC_WEBMENTION_ENABLE || false,
AUTH: process.env.NEXT_PUBLIC_WEBMENTION_AUTH || '',
HOSTNAME: process.env.NEXT_PUBLIC_WEBMENTION_HOSTNAME || '',
TWITTER_USERNAME: process.env.NEXT_PUBLIC_TWITTER_USERNAME || '',
TOKEN: process.env.NEXT_PUBLIC_WEBMENTION_TOKEN || ''
},

// <---- 评论插件

// ----> 站点统计
Expand Down
10 changes: 10 additions & 0 deletions components/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const GiscusComponent = dynamic(
},
{ ssr: false }
)
const WebMentionComponent = dynamic(
() => {
return import('@/components/WebMention')
},
{ ssr: false }
)

const ValineComponent = dynamic(() => import('@/components/ValineComponent'), {
ssr: false
Expand Down Expand Up @@ -100,6 +106,10 @@ const Comment = ({ frontMatter }) => {
{BLOG.COMMENT_GITALK_CLIENT_ID && (<div key='GitTalk'>
<GitalkComponent frontMatter={frontMatter}/>
</div>)}

{BLOG.COMMENT_WEBMENTION.ENABLE && (<div key='WebMention'>
<WebMentionComponent frontMatter={frontMatter} className="px-2" />
</div>)}
</Tabs>
</div>
)
Expand Down
10 changes: 10 additions & 0 deletions components/CommonHead.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ const CommonHead = ({ meta, children }) => {
<meta name="twitter:description" content={description} />
<meta name="twitter:title" content={title} />

{BLOG.COMMENT_WEBMENTION.ENABLE && (
<>
<link rel="webmention" href={`https://webmention.io/${BLOG.COMMENT_WEBMENTION.HOSTNAME}/webmention`} />
<link rel="pingback" href={`https://webmention.io/${BLOG.COMMENT_WEBMENTION.HOSTNAME}/xmlrpc`} />
</>
)}
{BLOG.COMMENT_WEBMENTION.ENABLE && BLOG.COMMENT_WEBMENTION.AUTH !== '' && (
<link href={BLOG.COMMENT_WEBMENTION.AUTH} rel="me" />
)}

{JSON.parse(BLOG.ANALYTICS_BUSUANZI_ENABLE) && <meta name="referrer" content="no-referrer-when-downgrade" />}
{meta?.type === 'Post' && (
<>
Expand Down
4 changes: 2 additions & 2 deletions components/NotionIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const NotionIcon = ({ icon }) => {
return <></>
}

if (icon.startsWith('http')) {
if (icon.startsWith('http') || icon.startsWith('data:')) {
// return <Image src={icon} width={30} height={30}/>
// eslint-disable-next-line @next/next/no-img-element
return <img src={icon} className='w-8 float-left mr-1'/>
return <img src={icon} className='w-8 inline mr-1'/>
}

return <span className='mr-1'>{icon}</span>
Expand Down
4 changes: 2 additions & 2 deletions components/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const Player = () => {
const [player, setPlayer] = React.useState()
const ref = React.useRef(null)

const showLrc = JSON.parse(BLOG.MUSIC_PLAYER_SHOW_LRC)
const lrcType = JSON.parse(BLOG.MUSIC_PLAYER_LRC_TYPE)
const playerVisible = JSON.parse(BLOG.MUSIC_PLAYER_VISIBLE)
const autoPlay = JSON.parse(BLOG.MUSIC_PLAYER_AUTO_PLAY)

Expand All @@ -16,7 +16,7 @@ const Player = () => {
setPlayer(new window.APlayer({
container: ref.current,
fixed: true,
showlrc: showLrc,
lrcType: lrcType,
autoplay: autoPlay,
mutex: true,
order: BLOG.MUSIC_PLAYER_ORDER,
Expand Down
173 changes: 173 additions & 0 deletions components/WebMention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import BLOG from '@/blog.config'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/router'
import Image from 'next/image'

/**
* 评论插件
* @param issueTerm
* @param layout
* @returns {JSX.Element}
* @constructor
*/
const WebmentionCount = ({ target }) => {
const initialCounts = {
count: 0,
type: {
like: 0,
mention: 0,
reply: 0,
repost: 0
}
}
const [counts, setCounts] = useState(initialCounts)
const fetchCounts = async (target) => {
const responseData = await fetch(`https://webmention.io/api/count.json?target=${encodeURIComponent(target)}`)
return (responseData.json) ? await responseData.json() : responseData
}
useEffect(() => {
async function getCounts() {
const responseCounts = await fetchCounts(target)
setCounts(responseCounts)
}
getCounts()
}, [target])

return (
<div className='webmention-counts'>
{counts
? (
<div className='counts'>
<span>
<span className='count'>{counts.type.like || 0}</span>Likes
</span>
<span>
<span className='count'>{counts.type.reply || 0}</span>Replies
</span>
<span>
<span className='count'>
{(counts.type.repost || 0) + (counts.type.mention || 0)}
</span>
Mentions
</span>
</div>
)
: (
<p>Failed to fetch Webmention counts</p>
)
}
</div>
)
}

const Avatar = ({ author }) => (
<a className='avatar-wrapper' href={author.url} key={author.name}>
<Image
className="avatar"
src={author.photo}
alt={author.name}
fill
sizes="(max-width: 768px) 100vw,
(max-width: 1200px) 50vw,
33vw"
/>
</a>
)

const WebmentionReplies = ({ target }) => {
const [mentions, setMentions] = useState([])
const fetchMentions = async (target) =>
fetch(
`https://webmention.io/api/mentions.jf2?per-page=500&target=${encodeURIComponent(target)}&token=${BLOG.COMMENT_WEBMENTION.TOKEN}`
).then((response) => (response.json ? response.json() : response))
useEffect(() => {
async function getMentions() {
const responseMentions = await fetchMentions(target)
if (responseMentions.children) {
setMentions(responseMentions.children)
}
}

getMentions()
}, [target])

const distinctMentions = [
...new Map(mentions.map((item) => [item.author.url, item])).values()
].sort((a, b) => new Date(a['wm-received']) - new Date(b['wm-received']))

const replies = mentions.filter(
(mention) => 'in-reply-to' in mention && 'content' in mention
)

return (
<div>
<p>
{distinctMentions.length > 0
? `Already ${distinctMentions.length} people liked, shared or talked about this article:`
: 'Be the first one to share this article!'}
</p>
<div className='webmention-avatars'>
{distinctMentions.map((reply) => (
<Avatar key={reply.author.name} author={reply.author} />
))}
</div>
{replies && replies.length
? (
<div className='webmention-replies'>
<h4>Replies</h4>
<ul className='replies'>
{replies.map((reply) => (
<li className='reply' key={reply.content.text}>
<div>
<Avatar key={reply.author.name} author={reply.author} />
</div>
<div className='text'>
<p className='reply-author-name'>{reply.author.name}</p>
<p className='reply-content'>{reply.content.text}</p>
</div>
</li>
))}
</ul>
</div>
)
: null}
</div>
)
}

const WebMentionBlock = ({ frontMatter }) => {
const router = useRouter()
const url = `https://${BLOG.COMMENT_WEBMENTION.HOSTNAME}${router.asPath}`
const tweet = `${frontMatter.title} by @${BLOG.COMMENT_WEBMENTION.TWITTER_USERNAME} ${url}`

return (
<div className='webmention-block'>
<h1 className='webmention-header'>
powered by <a href="https://webmention.io" target='_blank' rel='noreferrer'>WebMention.io</a>
</h1>
<div className='webmention-block-intro'>
You can{' '}
<a
target="_blank"
id='tweet-post-url'
href={`https://twitter.com/intent/tweet?text=${encodeURIComponent(tweet)}`}
rel="noopener noreferrer"
>tweet this post</a>{' '}
or{' '}
<a
target='_blank'
id='tweet-discuss-url'
href={`https://www.twitter.com/search?q=${url}`}
rel='noopener noreferrer'
>discuss it on Twitter</a>
, the comments will show up here.
</div>
<div className='webmention-info'>
<WebmentionCount target={url} />
<WebmentionReplies target={url} />
</div>
</div>
)
}

export default WebMentionBlock
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = withBundleAnalyzer({
'avatars.githubusercontent.com',
'images.unsplash.com',
'source.unsplash.com',
'p1.qhimg.com'
'p1.qhimg.com',
'webmention.io'
]
},
// 默认将feed重定向至 /public/rss/feed.xml
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notion-next",
"version": "3.13.2",
"version": "3.13.3",
"homepage": "https://github.com/tangly1024/NotionNext.git",
"license": "MIT",
"repository": {
Expand Down
Loading

1 comment on commit 28e7ef8

@vercel
Copy link

@vercel vercel bot commented on 28e7ef8 Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.