代码拉取完成,页面将自动刷新
同步操作将从 qingyunshangxing/poetry-source 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button id="download">下载索引</button>
<button id="downloadAuthorSql">下载作者表结构</button>
<button id="downloadPoetrySql">下载内容表结构</button>
<script src="./js/util/saveData.js"></script>
<script src="./js/index/file_path_idx.js"></script>
<script>
let log = console.log.bind(console)
// 异步请求
let httpRequest = function (url) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
resolve(JSON.parse(xhr.responseText));
}
}
xhr.send();
})
}
let contentCutIndex = function (source) {
if (!source || !source.length) {
return 0
}
const cutChar = [',', '。', '?', '!']
let minIdx = source.length
for (let i = 0; i < cutChar.length; i++) {
let cutIndex = source.indexOf(cutChar[i])
if (cutIndex != -1) {
minIdx = Math.min(minIdx, cutIndex)
}
}
return minIdx;
}
let main_author = [
"苏轼", "李白", "陆游", "王维", "杜甫", "杜牧", "屈原", "柳永", "李煜",
"王勃", "李贺", "秦观", "曹操", "曹植", "李商隐", "辛弃疾", "李清照", "白居易",
"陶渊明", "温庭筠", "欧阳修", "晏几道", "刘禹锡", "孟浩然", "张若虚",
"陈子昂", "贺知章", "王昌龄", "孟郊", "贾岛", "周邦彦", "晏殊", "姜夔", "纳兰性德"
]
let is_main_index = true
let fullIndex = {}
let fileCount = file_path_idx.length
let dealFileCount = 0
function buildFullIndex() {
file_path_idx.forEach((path, f_idx) => {
httpRequest(`/source/${path}`).then(data => {
// console.log(path)
// console.log(data.length)
let currIndex = {}
data.map((item, i_idx) => {
if (is_main_index) {
if (main_author.includes(item.authorName)) {
currIndex[
`${item.dynasty}-${item.title}-${item.authorName}-${item.content ? item.content[0].substr(0, contentCutIndex(item.content[0])) : ''}`
] = `${f_idx}-${i_idx}`
}
} else {
currIndex[
`${item.dynasty}-${item.title}-${item.authorName}-${item.content ? item.content[0].substr(0, contentCutIndex(item.content[0])) : ''}`
] = `${f_idx}-${i_idx}`
}
})
return currIndex
}).then(idx_list => {
Object.assign(fullIndex, idx_list)
dealFileCount++
})
});
}
download.onclick = function () {
fullIndex = {}
dealFileCount = 0
buildFullIndex()
let timer = setInterval(() => {
if (dealFileCount !== fileCount) {
log("等待解析中..." + dealFileCount + "/" + fileCount)
} else {
clearInterval(timer);
log("已解析完成..." + dealFileCount + "/" + fileCount)
saveData.setDataConver({
name: `${is_main_index ? 'main' : 'full'}_data_index.js`,
data: 'search_data_index = ' + JSON.stringify(fullIndex)
})
}
}, 500)
// saveData.setDataConver({ name: 'full_data_index.json', data: JSON.stringify(fullIndex, null, 2) })
}
function sqlNormalize(inStr) {
if (Array.isArray(inStr)) {
inStr = inStr.join("\n")
}
return inStr.replace(/\r?\n/g, "\\n")
.replace(/'/g, "\\'")
}
function sqlBuilder(tableName, titleList, data, defaultMap) {
let columnSeg = titleList.map(title => `\`${title}\``).join(', ')
return data.map(
item => titleList.map(
title => item[title] ? `'${sqlNormalize(item[title])}'` :
defaultMap[title] ? `'${sqlNormalize(defaultMap[title])}'` : 'null'
).join(', ')
)
.map(seg => `insert into ${tableName} (${columnSeg}) values (${seg});`)
.join('\n');
}
downloadAuthorSql.onclick = function () {
let titleList = ['id', 'name', 'dynasty', 'birthYear', 'deathYear', 'desc']
httpRequest('source/作者.json').then(data => {
let sql = sqlBuilder('t_author', titleList, data)
saveData.setDataConver({
name: `author.sql`,
data: sql
})
})
}
downloadPoetrySql.onclick = function () {
let titleList = ['id', 'title', 'authorName', 'authorId', 'dynasty', 'appreciation', 'content', 'comment', 'translation', 'intro', 'foreword', 'annotation', 'kindCN']
let sqlList = []
let sql_file_idx = 0
file_path_idx.forEach((path, f_idx) => {
let kindCN = path.substr(0, 1)
httpRequest(`/source/${path}`).then(data => sqlBuilder('t_work', titleList, data, {kindCN: kindCN}))
.then(sql => {
dealFileCount++
sqlList.push(sql)
if (dealFileCount === fileCount) {
saveData.setDataConver({
name: `work_${sql_file_idx}.sql`,
data: sqlList.join('\n')
})
sql_file_idx++
sqlList = []
}
})
});
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。