Skip to content

Commit

Permalink
feat: 支持文档反馈
Browse files Browse the repository at this point in the history
  • Loading branch information
jiazengp committed Mar 16, 2024
1 parent 974c5ce commit 45516f9
Show file tree
Hide file tree
Showing 24 changed files with 989 additions and 85 deletions.
1 change: 1 addition & 0 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default defineConfig({
srcExclude: [],
scrollOffset: 'header',
cleanUrls: true,
lastUpdated: true,
sitemap: {
hostname: 'https://yuanshen.site',
},
Expand Down
31 changes: 31 additions & 0 deletions .vitepress/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ export const enConfig: LocaleSpecificConfig<
siteTitle: 'Genshin Interactive Map',
outlineTitle: 'On This Page',
logo: '/imgs/logo_256.png',
ui: {
button: {
submit: 'Submit',
cancel: 'Cancel',
},
},
docsFeedback: {
feedbackMsg: 'Was this document helpful?',
good: 'Yes',
bad: 'No',
feedbackFailMsg:
'Feedback failed, please retry or contact admin (QQ: 1961266616)!',
feedbackSuccessMsg: 'Feedback submitted successfully, thank you!',
badFeedbackSuccessMsg: 'Please specify any issues below~',
form: {
chooseIssues: 'Did you encounter these issues?',
translationIssue: 'Translation',
typosIssue: 'Typos/Punctuation',
ContentImgLinkIssue: 'Inaccurate Content, Image or Link',
feedbackDetail: 'Details/Suggestions',
feedbackTip: 'Describe issues or suggestions here',
otherIssue: 'Other (specify below)',
contactWay: 'Contact (optional)',
issueOptions: [
{ label: 'Page Display Error', value: 'pagedisplay-issue' },
{ label: 'Typos, Punctuation', value: 'typos-issue' },
{ label: 'Content, Image, Link Error', value: 'content-issue' },
{ label: 'Other Issues', value: 'other-issue' },
],
},
},
notFound: {
title: 'PAGE NOT FOUND',
quote:
Expand Down
32 changes: 32 additions & 0 deletions .vitepress/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@ export const frConfig: LocaleSpecificConfig<
"But if you don't change your direction, and if you keep looking, you may end up where you are heading.",
linkLabel: 'Take me home',
},
ui: {
button: {
submit: 'Soumettre',
cancel: 'Annuler',
},
},
docsFeedback: {
feedbackMsg: 'Ce document vous a-t-il été utile ?',
good: 'Utile',
bad: 'Pas utile',
feedbackFailMsg:
"Échec de la rétroaction, veuillez réessayer ou contacter l'administrateur (QQ : 1961266616) !",
feedbackSuccessMsg: 'Rétroaction soumise avec succès, merci !',
badFeedbackSuccessMsg: 'Veuillez spécifier les problèmes ci-dessous~',
form: {
chooseIssues: "Avez-vous rencontré l'un de ces problèmes ?",
translationIssue: 'Problème de traduction',
typosIssue: 'Erreurs de frappe/ponctuation',
ContentImgLinkIssue:
"Contenu inexact, problème de chargement d'image ou de lien",
feedbackDetail: 'Détails/Suggestions',
feedbackTip: 'Décrivez les problèmes rencontrés ou les suggestions ici',
otherIssue: 'Autres problèmes (spécifiez ci-dessous)',
contactWay: 'Coordonnées (facultatif)',
issueOptions: [
{ label: "Erreur d'affichage de page", value: 'pagedisplay-issue' },
{ label: 'Erreurs de frappe, ponctuation', value: 'typos-issue' },
{ label: 'Contenu, image, erreur de lien', value: 'content-issue' },
{ label: 'Autres problèmes', value: 'other-issue' },
],
},
},
team: {
title: '关于团队',
desc: '地图的背后是一个基本来自中国的团队,以下是部分成员的个人信息。',
Expand Down
33 changes: 33 additions & 0 deletions .vitepress/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@ export const jaConfig: LocaleSpecificConfig<
"But if you don't change your direction, and if you keep looking, you may end up where you are heading.",
linkLabel: 'Take me home',
},
ui: {
button: {
submit: '提出する',
cancel: 'キャンセル',
},
},
docsFeedback: {
feedbackMsg: 'このドキュメントは役立ちましたか?',
good: '役立つ',
bad: '役に立たない',
feedbackFailMsg:
'フィードバックが失敗しました。再試行するか、管理者に連絡してください(QQ:1961266616)!',
feedbackSuccessMsg:
'フィードバックが正常に送信されました。ありがとうございます!',
badFeedbackSuccessMsg: '以下の問題を具体的にお知らせください~',
form: {
chooseIssues: '以下の問題に遭遇しましたか?',
translationIssue: '翻訳の問題',
typosIssue: '誤字/句読点のエラー',
ContentImgLinkIssue:
'不正確なコンテンツ表現、画像読み込みエラー、またはリンクエラー',
feedbackDetail: '詳細/提案',
feedbackTip: 'ここに遭遇した問題や提案を説明してください',
otherIssue: 'その他の問題(以下で具体的に指定してください)',
contactWay: '連絡先(任意)',
issueOptions: [
{ label: 'ページ表示エラー', value: 'pagedisplay-issue' },
{ label: '誤字、句読点のエラー', value: 'typos-issue' },
{ label: 'コンテンツ、画像、リンクのエラー', value: 'content-issue' },
{ label: 'その他の問題', value: 'other-issue' },
],
},
},
team: {
title: '关于团队',
desc: '地图的背后是一个基本来自中国的团队,以下是部分成员的个人信息。',
Expand Down
28 changes: 28 additions & 0 deletions .vitepress/locales/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,32 @@ export interface CustomConfig {
address: string
}
>
ui: {
button: {
submit: string
cancel: string
}
}
docsFeedback: {
feedbackMsg: string
good: string
bad: string
badFeedbackSuccessMsg: string
feedbackFailMsg: string
feedbackSuccessMsg: string
form: {
chooseIssues: string
translationIssue: string
typosIssue: string
ContentImgLinkIssue: string
feedbackDetail: string
feedbackTip: string
otherIssue: string
contactWay: string
issueOptions: {
label: string
value: string
}[]
}
}
}
31 changes: 30 additions & 1 deletion .vitepress/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export const zhConfig: LocaleSpecificConfig<
ariaLabel: 'bilibili',
},
],

docFooter: {
prev: '上一页',
next: '下一页',
Expand All @@ -96,6 +95,36 @@ export const zhConfig: LocaleSpecificConfig<
sponsor: '支持我们',
editLink: '报告页面错误',
},
ui: {
button: {
submit: '提交',
cancel: '取消',
},
},
docsFeedback: {
feedbackMsg: '这篇文档是否对你有帮助?',
good: '有帮助',
bad: '无帮助',
feedbackFailMsg: '反馈失败,请重试或联系管理员(QQ:1961266616)!',
feedbackSuccessMsg: '提交成功,感谢你的反馈!',
badFeedbackSuccessMsg: '希望你能在下方告知我们具体问题~',
form: {
chooseIssues: '是否遇到以下问题?',
translationIssue: '翻译问题',
typosIssue: '错别字/标点符号',
ContentImgLinkIssue: '文案表达不准确、图片加载失败或链接错误',
feedbackDetail: '反馈内容/更多建议',
feedbackTip: '请详细描述你在使用文档过程中遇到的问题或优化建议',
otherIssue: '其他问题(请在反馈内容中具体描述)',
contactWay: '联系方式(可选)',
issueOptions: [
{ label: '页面显示错误', value: 'pagedisplay-issue' },
{ label: '错别字、标点符号错误', value: 'typos-issue' },
{ label: '内容表达有误、图片/文字链接错误', value: 'content-issue' },
{ label: '其他问题', value: 'other-issue' },
],
},
},
payment: {
wechatpay: {
name: '微信支付',
Expand Down
23 changes: 23 additions & 0 deletions .vitepress/theme/apis/getPageInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { fetcher } from '.'

export type PageInfoResponse = {
code: number
message?: string
data: {
good: number
bad: number
pageview: number
lastupdate: number
id: string
record_id: string
}
}

export const getPageInfo = async (page): Promise<PageInfoResponse> =>
await fetcher
.get('docs/pageinfo', {
searchParams: {
path: String(page.value.filePath).replace('.md', ''),
},
})
.json()
29 changes: 29 additions & 0 deletions .vitepress/theme/apis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ky from 'ky'
import sha256 from 'crypto-js/sha256'
import hmacSHA512 from 'crypto-js/hmac-sha512'
import Base64 from 'crypto-js/enc-base64'

const hmacDigest = (date) =>
Base64.stringify(hmacSHA512(sha256(parseInt(date)), 'site.yuanshen'))

export const fetcher = ky.create({
prefixUrl: 'https://kongying-tavern-pin-feedback-api.vercel.app/apis/v1',
timeout: 5000,
retry: 0,
hooks: {
beforeRequest: [
(request) => {
const currently = Date.now()
request.headers.set(
'authorization',
`${currently}:${hmacDigest(currently)}`,
)
},
],
afterResponse: [
(_request, _options, response) => {
console.log(response)
},
],
},
})
55 changes: 55 additions & 0 deletions .vitepress/theme/apis/newDocFeedback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Content } from 'vitepress'
import { UAParser } from 'ua-parser-js'
import { fetcher } from '.'

const parser = new UAParser(window.navigator.userAgent)
const result = parser.getResult()

export type NewDocFeedbackResponse = {
code: number
message?: string
data?: {
id: string
feedback_id: string
record_id: string
}
}

export const newDocFeedback = async (data: {
path: string
feedback_type?: Array<string>
feedback_content?: string
user_id?: string
nickname?: string
file?: Array<string>
user_contact?: string
}): Promise<NewDocFeedbackResponse> => {
try {
return await fetcher
.post('docs/feedback/new', {
json: {
path: data.path,
feedback_type: data.feedback_type,
feedback_content: data.feedback_content,
user_id: data.user_id,
file: data.file,
nickname: data.nickname,
user_contract: data.user_contact,
user_platform: `${result.os.name}-${result.browser.name}`,
user_env_info: JSON.stringify({
userAgent: navigator.userAgent,
screen: {
availWidth: window.screen.availWidth,
availHeight: window.screen.availHeight,
width: window.screen.width,
height: window.screen.height,
},
}),
},
})
.json()
} catch (error) {
console.log(error)
return await error.response
}
}
15 changes: 15 additions & 0 deletions .vitepress/theme/apis/pageview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { fetcher } from '.'

export type PageviewResponse = {
code: number
message?: string
}

export const pageview = async (record_id): Promise<PageviewResponse> =>
await fetcher
.get('docs/pageview', {
searchParams: {
record_id,
},
})
.json()
21 changes: 21 additions & 0 deletions .vitepress/theme/apis/sendDocFeedback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { fetcher } from '.'

export type DocFeedbackResponse = {
code: number
message?: string
}

export const sendDocFeedback = async (
record_id: string,
type: 'good' | 'bad',
cancel?: boolean,
): Promise<DocFeedbackResponse> =>
await fetcher
.post('docs/feedback', {
json: {
record_id: record_id,
type: type,
cancel: cancel,
},
})
.json()
10 changes: 5 additions & 5 deletions .vitepress/theme/components/Banner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ref, onMounted, watchEffect } from 'vue'
import { useData } from 'vitepress'
import { hash } from '../utils'
import dayjs from 'dayjs'
const el = ref<HTMLElement>()
const { height } = useElementSize(el)
const banner = ref<HTMLElement>()
const { height } = useElementSize(banner)
const { frontmatter, page } = useData()
const storeKey = `banner-${page.value.relativePath}`
const isShow = ref(typeof frontmatter.value.banner === 'string')
const isBannerVisible = ref(typeof frontmatter.value.banner === 'string')
const deal = () => (Date.now() + 8.64e7 * 1).toString() // current time + 1 day
const inExpiryDate = () => {
if (!frontmatter.value.bannerExpiryDate) return false
Expand Down Expand Up @@ -54,14 +54,14 @@ const dismiss = () => {
}
const hideBanner = () => {
isShow.value = false
isBannerVisible.value = false
document.documentElement.style.setProperty('--vp-layout-top-height', '0.1px')
}
</script>

<template>
<ClientOnly>
<div v-show="isShow" ref="el" class="banner">
<div v-show="isBannerVisible" ref="banner" class="banner">
<div class="text" v-html="frontmatter.banner"></div>

<button type="button" @click="dismiss">
Expand Down
Loading

0 comments on commit 45516f9

Please sign in to comment.