@ablula/egg-yuque-viewer
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -24,3 +24,2 @@ 'use strict'; | ||
ctx.body = result; | ||
next(); | ||
}); | ||
@@ -58,24 +57,3 @@ } | ||
router.get(`GetDocumentView-${view}`, `${view}`, async (ctx, next) => { | ||
const directories = await yuqueClient.getDirectories(); | ||
ctx.body = `<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<link rel="icon" href="https://img.alicdn.com/tps/TB1kBU7NpXXXXXLXXXXXXXXXXXX-160-160.png" type="image/x-icon"> | ||
<link rel="shortcut icon" href="https://img.alicdn.com/tps/TB1kBU7NpXXXXXLXXXXXXXXXXXX-160-160.png"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>${_config.title || 'Ablula-Yuque'}</title> | ||
<link href="https://cdn.jsdelivr.net/npm/${_config.npm}/build/index.css" rel="stylesheet"></head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="mountNode"></div> | ||
<script>window.__INITIAL_STATE__ = ${JSON.stringify(Object.assign({ | ||
api: _config.prefix, | ||
searchAPI: _config.search, | ||
directories, | ||
}, _config))}</script> | ||
<script src="https://cdn.jsdelivr.net/npm/${_config.npm}/build/index.js"></script> | ||
</html>`; | ||
ctx.body = await yuqueClient.getDocumentView(); | ||
next(); | ||
@@ -82,0 +60,0 @@ }); |
@@ -68,5 +68,39 @@ 'use strict'; | ||
async getDocumentView() { | ||
const { config } = this; | ||
let directories = await this.getDirectories(); | ||
if (directories.length <= 20) { | ||
directories = await Promise.all(directories.map(async directory => { | ||
directory.document = await this.getDocument(directory.locator); | ||
return directory; | ||
})); | ||
} | ||
const themeStyleTag = config.themeStyle && `<link href="${config.themeStyle}" rel="stylesheet">` || null; | ||
return `<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<link rel="icon" href="https://img.alicdn.com/tps/TB1kBU7NpXXXXXLXXXXXXXXXXXX-160-160.png" type="image/x-icon"> | ||
<link rel="shortcut icon" href="https://img.alicdn.com/tps/TB1kBU7NpXXXXXLXXXXXXXXXXXX-160-160.png"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>${config.title || 'Ablula-Yuque'}</title> | ||
<link href="https://cdn.jsdelivr.net/npm/${config.npm}/build/index.css" rel="stylesheet"> | ||
${themeStyleTag || ''} | ||
</head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="mountNode"></div> | ||
<script>window.__INITIAL_STATE__ = ${JSON.stringify(Object.assign({ | ||
api: config.prefix, | ||
searchAPI: config.search, | ||
directories, | ||
}, config))}</script> | ||
<script src="https://cdn.jsdelivr.net/npm/${config.npm}/build/index.js"></script> | ||
</html>`; | ||
} | ||
async getDirectories() { | ||
const { app, config } = this; | ||
console.log('config: ', config); | ||
const namespace = config.namespace; | ||
@@ -73,0 +107,0 @@ const dirs = await this.request(`${this.baseUrl}/repos/${namespace}/toc`); |
{ | ||
"name": "@ablula/egg-yuque-viewer", | ||
"author": "mark.ck", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "egg plugin for yuque viewer", | ||
@@ -6,0 +6,0 @@ "eggPlugin": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10606
236