Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion __tests__/lib/utils/originalityProof.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ const post = {
}

describe('originalityProof', () => {
it('requires an explicit global or per-post opt-in', () => {
it('supports global opt-in, per-post opt-in, and metadata auto opt-in', () => {
expect(isOriginalityProofEnabled(false, {})).toBe(false)
expect(isOriginalityProofEnabled('true', {})).toBe(true)
expect(isOriginalityProofEnabled(false, { proof: 'yes' })).toBe(true)
expect(
isOriginalityProofEnabled(false, { proofUrl: 'https://proof.example' })
).toBe(true)
expect(isOriginalityProofEnabled(false, { ext: { proofHash: 'hash' } })).toBe(true)
expect(
isOriginalityProofEnabled(true, {
proof: 'false',
proofUrl: 'https://proof.example'
})
).toBe(false)
})

it('generates a deterministic content hash', () => {
Expand Down
25 changes: 23 additions & 2 deletions docs/user-guide/config/originality-proof.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@

## 开启方式

在部署环境变量中开启全站原创存证:
### 最省事:只给需要的文章填凭证

如果你已经有 GitHub、可信时间戳、版权平台或其他外部凭证,只需要在 Notion 文章数据库里填写下面任意一个字段,文章页就会自动显示原创存证块:

| 字段名 | 用途 |
| --- | --- |
| `proofHash` | 外部凭证记录的哈希 |
| `proofUrl` | 外部凭证链接 |

可选再填:

| 字段名 | 用途 |
| --- | --- |
| `proofTime` | 外部凭证或存证时间 |

也就是说,单篇文章最少只需要填一个 `proofUrl`,不必再额外填写 `proof=yes`。

### 全站开启

如果希望所有文章都生成并显示本地内容哈希,可以在部署环境变量中开启:

```bash
NEXT_PUBLIC_ORIGINALITY_PROOF_ENABLE=true
Expand All @@ -16,7 +35,9 @@ NEXT_PUBLIC_ORIGINALITY_PROOF_ENABLE=true

如果全站开启后有个别文章不想显示,在该文章的 `proof` 字段中填写 `false`。

如果只想给部分文章开启,可以保持全站关闭,并在 Notion 文章数据库中新增 `proof` 字段。需要显示原创存证的文章填写:
### 没有外部凭证时按单篇开启

如果没有外部凭证,只想让某篇文章显示 NotionNext 自动生成的本地内容哈希,可以保持全站关闭,并在 Notion 文章数据库中新增 `proof` 字段。需要显示原创存证的文章填写:

```txt
yes
Expand Down
15 changes: 14 additions & 1 deletion lib/utils/originalityProof.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ function hasValue(value) {
return value !== undefined && value !== null && String(value).trim() !== ''
}

function hasProofMetadata(post = {}) {
return (
hasValue(post.proofHash) ||
hasValue(post.proofUrl) ||
hasValue(post.ext?.proofHash) ||
hasValue(post.ext?.proofUrl)
)
}

export function isOriginalityProofEnabled(globalEnabled, post = {}) {
const localFlag = post.proof ?? post.originalityProof ?? post.ext?.proof

Expand All @@ -16,7 +25,11 @@ export function isOriginalityProofEnabled(globalEnabled, post = {}) {
)
}

return globalEnabled === true || globalEnabled === 'true'
return (
globalEnabled === true ||
globalEnabled === 'true' ||
hasProofMetadata(post)
)
}

function normalizeText(value) {
Expand Down
Loading