From d6ec5f2fe13bb1e3f4316f04591bf419f587c2bd Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 15 Dec 2017 00:23:45 +0900 Subject: :v: --- src/web/docs/api/gulpfile.ts | 156 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 src/web/docs/api/gulpfile.ts (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts new file mode 100644 index 0000000000..05567b6233 --- /dev/null +++ b/src/web/docs/api/gulpfile.ts @@ -0,0 +1,156 @@ +/** + * Gulp tasks + */ + +import * as fs from 'fs'; +import * as path from 'path'; +import * as glob from 'glob'; +import * as gulp from 'gulp'; +import * as pug from 'pug'; +import * as yaml from 'js-yaml'; +import * as mkdirp from 'mkdirp'; + +import config from './../../../conf'; + +const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); + +const parseParam = param => { + const id = param.type.match(/^id\((.+?)\)|^id/); + const entity = param.type.match(/^entity\((.+?)\)/); + const isObject = /^object/.test(param.type); + const isDate = /^date/.test(param.type); + const isArray = /\[\]$/.test(param.type); + if (id) { + param.kind = 'id'; + param.type = 'string'; + param.entity = id[1]; + if (isArray) { + param.type += '[]'; + } + } + if (entity) { + param.kind = 'entity'; + param.type = 'object'; + param.entity = entity[1]; + if (isArray) { + param.type += '[]'; + } + } + if (isObject) { + param.kind = 'object'; + } + if (isDate) { + param.kind = 'date'; + param.type = 'string'; + if (isArray) { + param.type += '[]'; + } + } + + return param; +}; + +const sortParams = params => { + params.sort((a, b) => { + if (a.name < b.name) + return -1; + if (a.name > b.name) + return 1; + return 0; + }); + return params; +}; + +const extractDefs = params => { + let defs = []; + + params.forEach(param => { + if (param.def) { + defs.push({ + name: param.defName, + params: sortParams(param.def.map(p => parseParam(p))) + }); + + const childDefs = extractDefs(param.def); + + defs = defs.concat(childDefs); + } + }); + + return defs; +}; + +gulp.task('doc:api', [ + 'doc:api:endpoints', + 'doc:api:entities' +]); + +gulp.task('doc:api:endpoints', () => { + glob('./src/web/docs/api/endpoints/**/*.yaml', (globErr, files) => { + if (globErr) { + console.error(globErr); + return; + } + //console.log(files); + files.forEach(file => { + const ep = yaml.safeLoad(fs.readFileSync(file, 'utf-8')); + const vars = { + endpoint: ep.endpoint, + url: `${config.api_url}/${ep.endpoint}`, + desc: ep.desc, + params: sortParams(ep.params.map(p => parseParam(p))), + paramDefs: extractDefs(ep.params), + res: sortParams(ep.res.map(p => parseParam(p))), + resDefs: extractDefs(ep.res), + kebab + }; + pug.renderFile('./src/web/docs/api/endpoints/view.pug', vars, (renderErr, html) => { + if (renderErr) { + console.error(renderErr); + return; + } + const htmlPath = `./built/web/docs/api/endpoints/${ep.endpoint}.html`; + mkdirp(path.dirname(htmlPath), (mkdirErr) => { + if (mkdirErr) { + console.error(mkdirErr); + return; + } + fs.writeFileSync(htmlPath, html, 'utf-8'); + }); + }); + }); + }); +}); + +gulp.task('doc:api:entities', () => { + glob('./src/web/docs/api/entities/**/*.yaml', (globErr, files) => { + if (globErr) { + console.error(globErr); + return; + } + files.forEach(file => { + const entity = yaml.safeLoad(fs.readFileSync(file, 'utf-8')); + const vars = { + name: entity.name, + desc: entity.desc, + props: sortParams(entity.props.map(p => parseParam(p))), + propDefs: extractDefs(entity.props), + kebab + }; + pug.renderFile('./src/web/docs/api/entities/view.pug', vars, (renderErr, html) => { + if (renderErr) { + console.error(renderErr); + return; + } + const htmlPath = `./built/web/docs/api/entities/${kebab(entity.name)}.html`; + mkdirp(path.dirname(htmlPath), (mkdirErr) => { + if (mkdirErr) { + console.error(mkdirErr); + return; + } + fs.writeFileSync(htmlPath, html, 'utf-8'); + }); + }); + }); + }); +}); -- cgit v1.2.3-freya From 13e4034ceee1e3983c852a2c40ce89eeb30dcecd Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 15 Dec 2017 00:54:28 +0900 Subject: :v: --- src/web/docs/api/entities/post.pug | 149 ------------------------------------ src/web/docs/api/entities/user.yaml | 137 +++++++++++++++++++++++++++++++++ src/web/docs/api/gulpfile.ts | 2 +- 3 files changed, 138 insertions(+), 150 deletions(-) delete mode 100644 src/web/docs/api/entities/post.pug create mode 100644 src/web/docs/api/entities/user.yaml (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/src/web/docs/api/entities/post.pug b/src/web/docs/api/entities/post.pug deleted file mode 100644 index 954f172717..0000000000 --- a/src/web/docs/api/entities/post.pug +++ /dev/null @@ -1,149 +0,0 @@ -extend ../../BASE - -block title - | Entity: Post - -block content - h1 Post - p 投稿を表します。 - - section - h2 Properties - table.entity - thead: tr - td Name - td Type - td Description - tbody - tr.nullable.optional - td app - td: a(href='./app', target='_blank') App - td 投稿したアプリ - tr.nullable - td app_id - td ID - td 投稿したアプリのID - tr - td created_at - td Date - td 投稿日時 - tr - td id - td ID - td 投稿ID - tr.optional - td is_liked - td Boolean - td いいね したかどうか - tr - td likes_count - td Number - td いいね数 - tr.nullable.optional - td media_ids - td ID[] - td 添付されたメディアのIDの配列 - tr.nullable.optional - td media - td: a(href='./drive-file', target='_blank') DriveFile[] - td 添付されたメディアの配列 - tr - td replies_count - td Number - td 返信数 - tr.optional - td reply - td: a(href='./post', target='_blank') Post - td 返信先の投稿 - tr.nullable - td reply_id - td ID - td 返信先の投稿のID - tr.optional - td repost - td: a(href='./post', target='_blank') Post - td Repostした投稿 - tr - td repost_count - td Number - td Repostされた数 - tr.nullable - td repost_id - td ID - td Repostした投稿のID - tr.nullable - td text - td String - td 本文 - tr.optional - td user - td: a(href='./user', target='_blank') User - td 投稿者 - tr - td user_id - td ID - td 投稿者のID - - section - h2 Example - pre: code. - { - "created_at": "2016-12-10T00:28:50.114Z", - "media_ids": null, - "reply_id": "584a16b15860fc52320137e3", - "repost_id": null, - "text": "小日向美穂だぞ!", - "user_id": "5848bf7764e572683f4402f8", - "app_id": null, - "likes_count": 1, - "replies_count": 1, - "id": "584b4c42d8e5186f8f755d0c", - "user": { - "birthday": null, - "created_at": "2016-12-08T02:03:35.332Z", - "bio": "女が嫌いです、女性は好きです", - "followers_count": 11, - "following_count": 11, - "links": null, - "location": "", - "name": "女が嫌い", - "posts_count": 26, - "likes_count": 2, - "liked_count": 20, - "username": "onnnagakirai", - "id": "5848bf7764e572683f4402f8", - "avatar_url": "https://file.himasaku.net/5848c0ec64e572683f4402fc", - "banner_url": "https://file.himasaku.net/5848c12864e572683f4402fd", - "is_following": true, - "is_followed": true - }, - "reply": { - "created_at": "2016-12-09T02:28:01.563Z", - "media_ids": null, - "reply_id": "5849d35e547e4249be329884", - "repost_id": null, - "text": "アイコン小日向美穂?", - "user_id": "57d01a501fdf2d07be417afe", - "app_id": null, - "replies_count": 1, - "id": "584a16b15860fc52320137e3", - "user": { - "birthday": null, - "created_at": "2016-09-07T13:46:56.605Z", - "bio": "どうすれば君だけのために生きていけるの", - "followers_count": 51, - "following_count": 97, - "links": null, - "location": "川崎", - "name": "きな子", - "posts_count": 4813, - "username": "syuilo", - "likes_count": 3141, - "liked_count": 750, - "id": "57d01a501fdf2d07be417afe", - "avatar_url": "https://file.himasaku.net/583ddc6e64df272771f74c1a", - "banner_url": "https://file.himasaku.net/584bfc82d8e5186f8f755ec5" - } - }, - "is_liked": true - } diff --git a/src/web/docs/api/entities/user.yaml b/src/web/docs/api/entities/user.yaml new file mode 100644 index 0000000000..9b1efd1fe6 --- /dev/null +++ b/src/web/docs/api/entities/user.yaml @@ -0,0 +1,137 @@ +name: "User" + +desc: + ja: "ユーザー。" + en: "A user." + +props: + - name: "id" + type: "id" + optional: false + desc: + ja: "ユーザーID" + en: "The ID of this user" + - name: "created_at" + type: "date" + optional: false + desc: + ja: "アカウント作成日時" + en: "The registered date of this user" + - name: "username" + type: "string" + optional: false + desc: + ja: "ユーザー名" + en: "The username of this user" + - name: "description" + type: "string" + optional: false + desc: + ja: "アカウントの説明(自己紹介)" + en: "The description of this user" + - name: "avatar_id" + type: "id(DriveFile)" + optional: true + desc: + ja: "アバターのID" + en: "The ID of the avatar of this user" + - name: "avatar_url" + type: "string" + optional: false + desc: + ja: "アバターのURL" + en: "The URL of the avatar of this user" + - name: "banner_id" + type: "id(DriveFile)" + optional: true + desc: + ja: "バナーのID" + en: "The ID of the banner of this user" + - name: "banner_url" + type: "string" + optional: false + desc: + ja: "バナーのURL" + en: "The URL of the banner of this user" + - name: "followers_count" + type: "number" + optional: false + desc: + ja: "フォロワーの数" + en: "The number of the followers for this user" + - name: "following_count" + type: "number" + optional: false + desc: + ja: "フォローしているユーザーの数" + en: "The number of the following users for this user" + - name: "last_used_at" + type: "date" + optional: false + desc: + ja: "最終利用日時" + en: "The last used date of this user" + - name: "posts_count" + type: "number" + optional: false + desc: + ja: "投稿の数" + en: "The number of the posts of this user" + - name: "pinned_post" + type: "entity(Post)" + optional: true + desc: + ja: "ピン留めされた投稿" + en: "The pinned post of this user" + - name: "pinned_post_id" + type: "id(Post)" + optional: true + desc: + ja: "ピン留めされた投稿のID" + en: "The ID of the pinned post of this user" + - name: "drive_capacity" + type: "number" + optional: false + desc: + ja: "ドライブの容量(bytes)" + en: "The capacity of drive of this user (bytes)" + - name: "twitter" + type: "object" + optional: true + desc: + ja: "連携されているTwitterアカウント情報" + en: "The info of the connected twitter account of this user" + defName: "twitter" + def: + - name: "user_id" + type: "string" + optional: false + desc: + ja: "ユーザーID" + en: "The user ID" + - name: "screen_name" + type: "string" + optional: false + desc: + ja: "ユーザー名" + en: "The screen name of this user" + - name: "profile" + type: "object" + optional: false + desc: + ja: "プロフィール" + en: "The profile of this user" + defName: "profile" + def: + - name: "location" + type: "string" + optional: true + desc: + ja: "場所" + en: "The location of this user" + - name: "birthday" + type: "string" + optional: true + desc: + ja: "誕生日 (YYYY-MM-DD)" + en: "The birthday of this user (YYYY-MM-DD)" diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 05567b6233..6453996d31 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -77,7 +77,7 @@ const extractDefs = params => { } }); - return defs; + return sortParams(defs); }; gulp.task('doc:api', [ -- cgit v1.2.3-freya From 169b99a358f166185147970b916adf1a09d23de3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 15 Dec 2017 06:41:57 +0900 Subject: :v: --- gulpfile.ts | 19 ++-------- src/web/docs/api/endpoints/view.pug | 3 +- src/web/docs/api/entities/view.pug | 2 +- src/web/docs/api/gulpfile.ts | 60 ++++++++++++++++++++------------ src/web/docs/api/mixins.pug | 6 ++-- src/web/docs/gulpfile.ts | 64 ++++++++++++++++++++++++++++++++++ src/web/docs/index.en.pug | 9 +++++ src/web/docs/index.ja.pug | 9 +++++ src/web/docs/index.md | 4 --- src/web/docs/layout.pug | 23 ++++++++++--- src/web/docs/style.styl | 69 +++++++++++++++++++++---------------- src/web/docs/vars.ts | 36 +++++++++++++++++++ 12 files changed, 220 insertions(+), 84 deletions(-) create mode 100644 src/web/docs/gulpfile.ts create mode 100644 src/web/docs/index.en.pug create mode 100644 src/web/docs/index.ja.pug delete mode 100644 src/web/docs/index.md create mode 100644 src/web/docs/vars.ts (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/gulpfile.ts b/gulpfile.ts index 6807b6d571..e7d4770610 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -13,7 +13,6 @@ import * as es from 'event-stream'; import cssnano = require('gulp-cssnano'); import * as uglifyComposer from 'gulp-uglify/composer'; import pug = require('gulp-pug'); -import stylus = require('gulp-stylus'); import * as rimraf from 'rimraf'; import chalk from 'chalk'; import imagemin = require('gulp-imagemin'); @@ -48,32 +47,18 @@ if (isDebug) { const constants = require('./src/const.json'); -require('./src/web/docs/api/gulpfile.ts'); +require('./src/web/docs/gulpfile.ts'); gulp.task('build', [ 'build:js', 'build:ts', 'build:copy', 'build:client', - 'build:doc' + 'doc' ]); gulp.task('rebuild', ['clean', 'build']); -gulp.task('build:doc', [ - 'doc:api', - 'doc:styles' -]); - -gulp.task('doc:styles', () => - gulp.src('./src/web/docs/**/*.styl') - .pipe(stylus()) - .pipe(isProduction - ? (cssnano as any)() - : gutil.noop()) - .pipe(gulp.dest('./built/web/assets/docs/')) -); - gulp.task('build:js', () => gulp.src(['./src/**/*.js', '!./src/web/**/*.js']) .pipe(gulp.dest('./built/')) diff --git a/src/web/docs/api/endpoints/view.pug b/src/web/docs/api/endpoints/view.pug index cebef9fa5b..cab814cabc 100644 --- a/src/web/docs/api/endpoints/view.pug +++ b/src/web/docs/api/endpoints/view.pug @@ -12,7 +12,7 @@ block main p#url= url - p#desc: +i18n(desc) + p#desc= desc[lang] || desc['ja'] section h2 Params @@ -27,4 +27,3 @@ block main section h2 Response +propTable(res) - diff --git a/src/web/docs/api/entities/view.pug b/src/web/docs/api/entities/view.pug index f210582f1a..756e966b53 100644 --- a/src/web/docs/api/entities/view.pug +++ b/src/web/docs/api/entities/view.pug @@ -10,7 +10,7 @@ block meta block main h1= name - p#desc: +i18n(desc) + p#desc= desc[lang] || desc['ja'] section h2 Properties diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 6453996d31..6cbae5ea2d 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -12,6 +12,12 @@ import * as mkdirp from 'mkdirp'; import config from './../../../conf'; +import generateVars from '../vars'; + +const commonVars = generateVars(); + +const langs = ['ja', 'en']; + const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); const parseParam = param => { @@ -102,20 +108,25 @@ gulp.task('doc:api:endpoints', () => { paramDefs: extractDefs(ep.params), res: sortParams(ep.res.map(p => parseParam(p))), resDefs: extractDefs(ep.res), - kebab + kebab, + common: commonVars }; - pug.renderFile('./src/web/docs/api/endpoints/view.pug', vars, (renderErr, html) => { - if (renderErr) { - console.error(renderErr); - return; - } - const htmlPath = `./built/web/docs/api/endpoints/${ep.endpoint}.html`; - mkdirp(path.dirname(htmlPath), (mkdirErr) => { - if (mkdirErr) { - console.error(mkdirErr); + langs.forEach(lang => { + pug.renderFile('./src/web/docs/api/endpoints/view.pug', Object.assign({}, vars, { + lang + }), (renderErr, html) => { + if (renderErr) { + console.error(renderErr); return; } - fs.writeFileSync(htmlPath, html, 'utf-8'); + const htmlPath = `./built/web/docs/${lang}/api/endpoints/${ep.endpoint}.html`; + mkdirp(path.dirname(htmlPath), (mkdirErr) => { + if (mkdirErr) { + console.error(mkdirErr); + return; + } + fs.writeFileSync(htmlPath, html, 'utf-8'); + }); }); }); }); @@ -135,20 +146,25 @@ gulp.task('doc:api:entities', () => { desc: entity.desc, props: sortParams(entity.props.map(p => parseParam(p))), propDefs: extractDefs(entity.props), - kebab + kebab, + common: commonVars }; - pug.renderFile('./src/web/docs/api/entities/view.pug', vars, (renderErr, html) => { - if (renderErr) { - console.error(renderErr); - return; - } - const htmlPath = `./built/web/docs/api/entities/${kebab(entity.name)}.html`; - mkdirp(path.dirname(htmlPath), (mkdirErr) => { - if (mkdirErr) { - console.error(mkdirErr); + langs.forEach(lang => { + pug.renderFile('./src/web/docs/api/entities/view.pug', Object.assign({}, vars, { + lang + }), (renderErr, html) => { + if (renderErr) { + console.error(renderErr); return; } - fs.writeFileSync(htmlPath, html, 'utf-8'); + const htmlPath = `./built/web/docs/${lang}/api/entities/${kebab(entity.name)}.html`; + mkdirp(path.dirname(htmlPath), (mkdirErr) => { + if (mkdirErr) { + console.error(mkdirErr); + return; + } + fs.writeFileSync(htmlPath, html, 'utf-8'); + }); }); }); }); diff --git a/src/web/docs/api/mixins.pug b/src/web/docs/api/mixins.pug index b302c78263..3ddd7cb48a 100644 --- a/src/web/docs/api/mixins.pug +++ b/src/web/docs/api/mixins.pug @@ -14,13 +14,13 @@ mixin propTable(props) if prop.kind == 'id' if prop.entity | ( - a(href=`/docs/api/entities/${kebab(prop.entity)}`)= prop.entity + a(href=`/docs/${lang}/api/entities/${kebab(prop.entity)}`)= prop.entity | ID) else | (ID) else if prop.kind == 'entity' | ( - a(href=`/docs/api/entities/${kebab(prop.entity)}`)= prop.entity + a(href=`/docs/${lang}/api/entities/${kebab(prop.entity)}`)= prop.entity | ) else if prop.kind == 'object' if prop.def @@ -30,4 +30,4 @@ mixin propTable(props) else if prop.kind == 'date' | (Date) td.optional= prop.optional.toString() - td.desc: +i18n(prop.desc) + td.desc!= prop.desc[lang] || prop.desc['ja'] diff --git a/src/web/docs/gulpfile.ts b/src/web/docs/gulpfile.ts new file mode 100644 index 0000000000..6f2351dacb --- /dev/null +++ b/src/web/docs/gulpfile.ts @@ -0,0 +1,64 @@ +/** + * Gulp tasks + */ + +import * as fs from 'fs'; +import * as path from 'path'; +import * as glob from 'glob'; +import * as gulp from 'gulp'; +import * as pug from 'pug'; +//import * as yaml from 'js-yaml'; +import * as mkdirp from 'mkdirp'; +import stylus = require('gulp-stylus'); +import cssnano = require('gulp-cssnano'); + +//import config from './../../conf'; + +import generateVars from './vars'; + +require('./api/gulpfile.ts'); + +gulp.task('doc', [ + 'doc:docs', + 'doc:api', + 'doc:styles' +]); + +const commonVars = generateVars(); + +gulp.task('doc:docs', () => { + glob('./src/web/docs/**/*.*.pug', (globErr, files) => { + if (globErr) { + console.error(globErr); + return; + } + files.forEach(file => { + const [, name, lang] = file.match(/docs\/(.+?)\.(.+?)\.pug$/); + const vars = { + common: commonVars, + lang: lang + }; + pug.renderFile(file, vars, (renderErr, html) => { + if (renderErr) { + console.error(renderErr); + return; + } + const htmlPath = `./built/web/docs/${lang}/${name}.html`; + mkdirp(path.dirname(htmlPath), (mkdirErr) => { + if (mkdirErr) { + console.error(mkdirErr); + return; + } + fs.writeFileSync(htmlPath, html, 'utf-8'); + }); + }); + }); + }); +}); + +gulp.task('doc:styles', () => + gulp.src('./src/web/docs/**/*.styl') + .pipe(stylus()) + .pipe((cssnano as any)()) + .pipe(gulp.dest('./built/web/assets/docs/')) +); diff --git a/src/web/docs/index.en.pug b/src/web/docs/index.en.pug new file mode 100644 index 0000000000..af0bba8b2c --- /dev/null +++ b/src/web/docs/index.en.pug @@ -0,0 +1,9 @@ +extends ./layout.pug + +block title + | Misskey Docs + +block main + h1 Misskey Docs + + p Welcome to docs of Misskey. diff --git a/src/web/docs/index.ja.pug b/src/web/docs/index.ja.pug new file mode 100644 index 0000000000..cd43045f6e --- /dev/null +++ b/src/web/docs/index.ja.pug @@ -0,0 +1,9 @@ +extends ./layout.pug + +block title + | Misskey ドキュメント + +block main + h1 Misskey ドキュメント + + p Misskeyのドキュメントへようこそ diff --git a/src/web/docs/index.md b/src/web/docs/index.md deleted file mode 100644 index 0846cf27e8..0000000000 --- a/src/web/docs/index.md +++ /dev/null @@ -1,4 +0,0 @@ -Misskeyについて -================================================================ - -誰か書いて diff --git a/src/web/docs/layout.pug b/src/web/docs/layout.pug index 68ca9eb62d..d6ecb4b6aa 100644 --- a/src/web/docs/layout.pug +++ b/src/web/docs/layout.pug @@ -1,16 +1,29 @@ doctype html -mixin i18n(xs) - each text, lang in xs - span(class=`i18n ${lang}`)!= text - -html +html(lang= lang) head meta(charset="UTF-8") + meta(name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no") title block title + link(rel="stylesheet" href="/assets/docs/style.css") block meta body + nav + ul + each doc in common.docs + li: a(href=`/docs/${lang}/${doc.name}`)= doc.title[lang] || doc.title['ja'] + section + h2 API + ul + li Entities + ul + each entity in common.entities + li: a(href=`/docs/${lang}/api/entities/${common.kebab(entity)}`)= entity + li Endpoints + ul + each endpoint in common.endpoints + li: a(href=`/docs/${lang}/api/endpoints/${common.kebab(endpoint)}`)= endpoint main block main diff --git a/src/web/docs/style.styl b/src/web/docs/style.styl index a4abc5a9a3..2e2f9f5743 100644 --- a/src/web/docs/style.styl +++ b/src/web/docs/style.styl @@ -5,10 +5,49 @@ body color #34495e main + margin 0 0 0 256px padding 32px width 100% max-width 700px + section + margin 32px 0 + + h1 + margin 0 0 24px 0 + padding 16px 0 + font-size 1.5em + border-bottom solid 2px #eee + + h2 + margin 0 0 24px 0 + padding 0 0 16px 0 + font-size 1.4em + border-bottom solid 1px #eee + + h3 + margin 0 + padding 0 + font-size 1.25em + + h4 + margin 0 + + p + margin 1em 0 + line-height 1.6em + +nav + display block + position fixed + top 0 + left 0 + width 256px + height 100% + overflow auto + padding 32px + border-right solid 2px #eee + footer padding:32px 0 0 0 margin 32px 0 0 0 @@ -18,33 +57,6 @@ footer margin 16px 0 0 0 color #aaa -section - margin 32px 0 - -h1 - margin 0 0 24px 0 - padding 16px 0 - font-size 1.5em - border-bottom solid 2px #eee - -h2 - margin 0 0 24px 0 - padding 0 0 16px 0 - font-size 1.4em - border-bottom solid 1px #eee - -h3 - margin 0 - padding 0 - font-size 1.25em - -h4 - margin 0 - -p - margin 1em 0 - line-height 1.6em - table width 100% border-spacing 0 @@ -72,6 +84,3 @@ table th, td padding 8px 16px - -.i18n:not(.ja) - display none diff --git a/src/web/docs/vars.ts b/src/web/docs/vars.ts new file mode 100644 index 0000000000..ed2149df4a --- /dev/null +++ b/src/web/docs/vars.ts @@ -0,0 +1,36 @@ +import * as fs from 'fs'; +import * as glob from 'glob'; +import * as yaml from 'js-yaml'; + +export default function() { + const vars = {}; + + const endpoints = glob.sync('./src/web/docs/api/endpoints/**/*.yaml'); + vars['endpoints'] = endpoints.map(ep => { + const _ep = yaml.safeLoad(fs.readFileSync(ep, 'utf-8')); + return _ep.endpoint; + }); + + const entities = glob.sync('./src/web/docs/api/entities/**/*.yaml'); + vars['entities'] = entities.map(x => { + const _x = yaml.safeLoad(fs.readFileSync(x, 'utf-8')); + return _x.name; + }); + + const docs = glob.sync('./src/web/docs/**/*.*.pug'); + vars['docs'] = {}; + docs.forEach(x => { + const [, name, lang] = x.match(/docs\/(.+?)\.(.+?)\.pug$/); + if (vars['docs'][name] == null) { + vars['docs'][name] = { + name, + title: {} + }; + } + vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/\r\n\th1 (.+?)\r\n/)[1]; + }); + + vars['kebab'] = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); + + return vars; +} -- cgit v1.2.3-freya From e1cc715589f83147b64a76bf0962b7a77dd2d19c Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 16 Dec 2017 00:19:10 +0900 Subject: :v: --- src/web/docs/api/endpoints/view.pug | 3 --- src/web/docs/api/entities/view.pug | 3 --- src/web/docs/api/gulpfile.ts | 14 ++++++++------ src/web/docs/gulpfile.ts | 24 +++++++++++++++++------- src/web/docs/index.en.pug | 10 ++-------- src/web/docs/index.ja.pug | 10 ++-------- src/web/docs/layout.pug | 4 +++- src/web/docs/vars.ts | 2 +- 8 files changed, 33 insertions(+), 37 deletions(-) (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/src/web/docs/api/endpoints/view.pug b/src/web/docs/api/endpoints/view.pug index cab814cabc..d456022f6e 100644 --- a/src/web/docs/api/endpoints/view.pug +++ b/src/web/docs/api/endpoints/view.pug @@ -1,9 +1,6 @@ extends ../../layout.pug include ../mixins -block title - | #{endpoint} | Misskey API - block meta link(rel="stylesheet" href="/assets/docs/api/endpoints/style.css") diff --git a/src/web/docs/api/entities/view.pug b/src/web/docs/api/entities/view.pug index 756e966b53..57c6d4cad7 100644 --- a/src/web/docs/api/entities/view.pug +++ b/src/web/docs/api/entities/view.pug @@ -1,9 +1,6 @@ extends ../../layout.pug include ../mixins -block title - | #{name} | Misskey API - block meta link(rel="stylesheet" href="/assets/docs/api/entities/style.css") diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 6cbae5ea2d..139ae92412 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -108,12 +108,13 @@ gulp.task('doc:api:endpoints', () => { paramDefs: extractDefs(ep.params), res: sortParams(ep.res.map(p => parseParam(p))), resDefs: extractDefs(ep.res), - kebab, - common: commonVars }; langs.forEach(lang => { pug.renderFile('./src/web/docs/api/endpoints/view.pug', Object.assign({}, vars, { - lang + lang, + title: ep.endpoint, + kebab, + common: commonVars }), (renderErr, html) => { if (renderErr) { console.error(renderErr); @@ -146,12 +147,13 @@ gulp.task('doc:api:entities', () => { desc: entity.desc, props: sortParams(entity.props.map(p => parseParam(p))), propDefs: extractDefs(entity.props), - kebab, - common: commonVars }; langs.forEach(lang => { pug.renderFile('./src/web/docs/api/entities/view.pug', Object.assign({}, vars, { - lang + lang, + title: entity.name, + kebab, + common: commonVars }), (renderErr, html) => { if (renderErr) { console.error(renderErr); diff --git a/src/web/docs/gulpfile.ts b/src/web/docs/gulpfile.ts index 6f2351dacb..2377844650 100644 --- a/src/web/docs/gulpfile.ts +++ b/src/web/docs/gulpfile.ts @@ -36,20 +36,30 @@ gulp.task('doc:docs', () => { const [, name, lang] = file.match(/docs\/(.+?)\.(.+?)\.pug$/); const vars = { common: commonVars, - lang: lang + lang: lang, + title: fs.readFileSync(file, 'utf-8').match(/^h1 (.+?)\r?\n/)[1] }; - pug.renderFile(file, vars, (renderErr, html) => { + pug.renderFile(file, vars, (renderErr, content) => { if (renderErr) { console.error(renderErr); return; } - const htmlPath = `./built/web/docs/${lang}/${name}.html`; - mkdirp(path.dirname(htmlPath), (mkdirErr) => { - if (mkdirErr) { - console.error(mkdirErr); + + pug.renderFile('./src/web/docs/layout.pug', Object.assign({}, vars, { + content + }), (renderErr2, html) => { + if (renderErr2) { + console.error(renderErr2); return; } - fs.writeFileSync(htmlPath, html, 'utf-8'); + const htmlPath = `./built/web/docs/${lang}/${name}.html`; + mkdirp(path.dirname(htmlPath), (mkdirErr) => { + if (mkdirErr) { + console.error(mkdirErr); + return; + } + fs.writeFileSync(htmlPath, html, 'utf-8'); + }); }); }); }); diff --git a/src/web/docs/index.en.pug b/src/web/docs/index.en.pug index af0bba8b2c..1fcc870d3d 100644 --- a/src/web/docs/index.en.pug +++ b/src/web/docs/index.en.pug @@ -1,9 +1,3 @@ -extends ./layout.pug +h1 Misskey Docs -block title - | Misskey Docs - -block main - h1 Misskey Docs - - p Welcome to docs of Misskey. +p Welcome to docs of Misskey. diff --git a/src/web/docs/index.ja.pug b/src/web/docs/index.ja.pug index cd43045f6e..4a0bf7fa1d 100644 --- a/src/web/docs/index.ja.pug +++ b/src/web/docs/index.ja.pug @@ -1,9 +1,3 @@ -extends ./layout.pug +h1 Misskey ドキュメント -block title - | Misskey ドキュメント - -block main - h1 Misskey ドキュメント - - p Misskeyのドキュメントへようこそ +p Misskeyのドキュメントへようこそ diff --git a/src/web/docs/layout.pug b/src/web/docs/layout.pug index d6ecb4b6aa..f8570dd3ac 100644 --- a/src/web/docs/layout.pug +++ b/src/web/docs/layout.pug @@ -5,7 +5,7 @@ html(lang= lang) meta(charset="UTF-8") meta(name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no") title - block title + | #{title} | Misskey Docs link(rel="stylesheet" href="/assets/docs/style.css") block meta @@ -27,3 +27,5 @@ html(lang= lang) li: a(href=`/docs/${lang}/api/endpoints/${common.kebab(endpoint)}`)= endpoint main block main + if content + | !{content} diff --git a/src/web/docs/vars.ts b/src/web/docs/vars.ts index 80fdc9a7de..37bc9d7b0f 100644 --- a/src/web/docs/vars.ts +++ b/src/web/docs/vars.ts @@ -27,7 +27,7 @@ export default function() { title: {} }; } - vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/\r?\n\th1 (.+?)\r?\n/)[1]; + vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1]; }); vars['kebab'] = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); -- cgit v1.2.3-freya From 446b6a4f6bb376abdd6ebee5546f568d8c5dbc83 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 16 Dec 2017 05:04:02 +0900 Subject: :v: --- src/web/docs/api/endpoints/posts/timeline.yaml | 32 ++++++++++++++++++++++++++ src/web/docs/api/endpoints/view.pug | 7 +++--- src/web/docs/api/gulpfile.ts | 4 ++-- 3 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/web/docs/api/endpoints/posts/timeline.yaml (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/src/web/docs/api/endpoints/posts/timeline.yaml b/src/web/docs/api/endpoints/posts/timeline.yaml new file mode 100644 index 0000000000..e1d78c082e --- /dev/null +++ b/src/web/docs/api/endpoints/posts/timeline.yaml @@ -0,0 +1,32 @@ +endpoint: "posts/timeline" + +desc: + ja: "タイムラインを取得します。" + en: "Get your timeline." + +params: + - name: "limit" + type: "number" + optional: true + desc: + ja: "取得する最大の数" + - name: "since_id" + type: "id(Post)" + optional: true + desc: + ja: "指定すると、この投稿を基点としてより新しい投稿を取得します" + - name: "max_id" + type: "id(Post)" + optional: true + desc: + ja: "指定すると、この投稿を基点としてより古い投稿を取得します" + - name: "since_date" + type: "number" + optional: true + desc: + ja: "指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。" + - name: "max_date" + type: "number" + optional: true + desc: + ja: "指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。" diff --git a/src/web/docs/api/endpoints/view.pug b/src/web/docs/api/endpoints/view.pug index d456022f6e..62a6f59edd 100644 --- a/src/web/docs/api/endpoints/view.pug +++ b/src/web/docs/api/endpoints/view.pug @@ -21,6 +21,7 @@ block main h3= paramDef.name +propTable(paramDef.params) - section - h2 Response - +propTable(res) + if res + section + h2 Response + +propTable(res) diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 139ae92412..908280453c 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -106,8 +106,8 @@ gulp.task('doc:api:endpoints', () => { desc: ep.desc, params: sortParams(ep.params.map(p => parseParam(p))), paramDefs: extractDefs(ep.params), - res: sortParams(ep.res.map(p => parseParam(p))), - resDefs: extractDefs(ep.res), + res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null, + resDefs: ep.res ? extractDefs(ep.res) : null, }; langs.forEach(lang => { pug.renderFile('./src/web/docs/api/endpoints/view.pug', Object.assign({}, vars, { -- cgit v1.2.3-freya From da279f9e50839da68746ad6460045d0f358818ae Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 17 Dec 2017 04:02:30 +0900 Subject: :v: --- locales/en.yml | 18 ++++++++++++++++++ locales/index.ts | 23 +++++++++++++++++++++++ locales/ja.yml | 18 ++++++++++++++++++ src/web/docs/api/endpoints/style.styl | 15 ++++++++++++++- src/web/docs/api/endpoints/view.pug | 11 ++++++++--- src/web/docs/api/entities/view.pug | 2 +- src/web/docs/api/gulpfile.ts | 9 +++++++-- src/web/docs/api/mixins.pug | 14 +++++++++----- src/web/docs/gulpfile.ts | 3 ++- src/web/docs/layout.pug | 12 +++++++++--- src/web/docs/style.styl | 17 ++++++++--------- src/web/docs/vars.ts | 7 +++++-- webpack/langs.ts | 23 ----------------------- webpack/webpack.config.ts | 4 ++-- 14 files changed, 124 insertions(+), 52 deletions(-) create mode 100644 locales/index.ts delete mode 100644 webpack/langs.ts (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/locales/en.yml b/locales/en.yml index b49af68bdf..57e0c4116f 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -183,6 +183,24 @@ common: mk-uploader: waiting: "Waiting" +docs: + edit-this-page-on-github: "Caught a mistake or want to contribute to the documentation? " + edit-this-page-on-github-link: "Edit this page on Github!" + + api: + entities: + properties: "Properties" + endpoints: + params: "Parameters" + res: "Response" + props: + name: "Name" + type: "Type" + optional: "Optional" + description: "Description" + yes: "Yes" + no: "No" + ch: tags: mk-index: diff --git a/locales/index.ts b/locales/index.ts new file mode 100644 index 0000000000..0593af366c --- /dev/null +++ b/locales/index.ts @@ -0,0 +1,23 @@ +/** + * Languages Loader + */ + +import * as fs from 'fs'; +import * as yaml from 'js-yaml'; + +const loadLang = lang => yaml.safeLoad( + fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')); + +const native = loadLang('ja'); + +const langs = { + 'en': loadLang('en'), + 'ja': native +}; + +Object.entries(langs).map(([, locale]) => { + // Extend native language (Japanese) + locale = Object.assign({}, native, locale); +}); + +export default langs; diff --git a/locales/ja.yml b/locales/ja.yml index afafa5a63a..ee52f07166 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -183,6 +183,24 @@ common: mk-uploader: waiting: "待機中" +docs: + edit-this-page-on-github: "間違いや改善点を見つけましたか?" + edit-this-page-on-github-link: "このページをGitHubで編集" + + api: + entities: + properties: "プロパティ" + endpoints: + params: "パラメータ" + res: "レスポンス" + props: + name: "名前" + type: "型" + optional: "オプション" + description: "説明" + yes: "はい" + no: "いいえ" + ch: tags: mk-index: diff --git a/src/web/docs/api/endpoints/style.styl b/src/web/docs/api/endpoints/style.styl index 07fb7ec2a3..2af9fe9a77 100644 --- a/src/web/docs/api/endpoints/style.styl +++ b/src/web/docs/api/endpoints/style.styl @@ -1,8 +1,21 @@ @import "../style" #url - padding 8px 12px + padding 8px 12px 8px 8px font-family Consolas, 'Courier New', Courier, Monaco, monospace color #fff background #222e40 border-radius 4px + + > .method + display inline-block + margin 0 8px 0 0 + padding 0 6px + color #f4fcff + background #17afc7 + border-radius 4px + user-select none + pointer-events none + + > .host + opacity 0.7 diff --git a/src/web/docs/api/endpoints/view.pug b/src/web/docs/api/endpoints/view.pug index 9ba1c4e852..90084ab276 100644 --- a/src/web/docs/api/endpoints/view.pug +++ b/src/web/docs/api/endpoints/view.pug @@ -7,12 +7,17 @@ block meta block main h1= endpoint - p#url= url + p#url + span.method POST + span.host + = url.host + | / + span.path= url.path p#desc= desc[lang] || desc['ja'] section - h2 Params + h2= common.i18n[lang]['docs']['api']['endpoints']['params'] +propTable(params) if paramDefs @@ -23,5 +28,5 @@ block main if res section - h2 Response + h2= common.i18n[lang]['docs']['api']['endpoints']['res'] +propTable(res) diff --git a/src/web/docs/api/entities/view.pug b/src/web/docs/api/entities/view.pug index 6fc05bd555..99e786c694 100644 --- a/src/web/docs/api/entities/view.pug +++ b/src/web/docs/api/entities/view.pug @@ -10,7 +10,7 @@ block main p#desc= desc[lang] || desc['ja'] section - h2 Properties + h2= common.i18n[lang]['docs']['api']['entities']['properties'] +propTable(props) if propDefs diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 908280453c..2e8409c595 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -16,7 +16,7 @@ import generateVars from '../vars'; const commonVars = generateVars(); -const langs = ['ja', 'en']; +const langs = Object.keys(commonVars.i18n); const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); @@ -102,7 +102,10 @@ gulp.task('doc:api:endpoints', () => { const ep = yaml.safeLoad(fs.readFileSync(file, 'utf-8')); const vars = { endpoint: ep.endpoint, - url: `${config.api_url}/${ep.endpoint}`, + url: { + host: config.api_url, + path: ep.endpoint + }, desc: ep.desc, params: sortParams(ep.params.map(p => parseParam(p))), paramDefs: extractDefs(ep.params), @@ -113,6 +116,7 @@ gulp.task('doc:api:endpoints', () => { pug.renderFile('./src/web/docs/api/endpoints/view.pug', Object.assign({}, vars, { lang, title: ep.endpoint, + src: `https://github.com/syuilo/misskey/tree/master/src/web/docs/api/endpoints/${ep.endpoint}.yaml`, kebab, common: commonVars }), (renderErr, html) => { @@ -152,6 +156,7 @@ gulp.task('doc:api:entities', () => { pug.renderFile('./src/web/docs/api/entities/view.pug', Object.assign({}, vars, { lang, title: entity.name, + src: `https://github.com/syuilo/misskey/tree/master/src/web/docs/api/entities/${kebab(entity.name)}.yaml`, kebab, common: commonVars }), (renderErr, html) => { diff --git a/src/web/docs/api/mixins.pug b/src/web/docs/api/mixins.pug index 5180698574..b563a121db 100644 --- a/src/web/docs/api/mixins.pug +++ b/src/web/docs/api/mixins.pug @@ -1,10 +1,10 @@ mixin propTable(props) table.props thead: tr - th Name - th Type - th Optional - th Description + th= common.i18n[lang]['docs']['api']['props']['name'] + th= common.i18n[lang]['docs']['api']['props']['type'] + th= common.i18n[lang]['docs']['api']['props']['optional'] + th= common.i18n[lang]['docs']['api']['props']['description'] tbody each prop in props tr @@ -29,5 +29,9 @@ mixin propTable(props) | ) else if prop.kind == 'date' | (Date) - td.optional= prop.optional.toString() + td.optional + if prop.optional + = common.i18n[lang]['docs']['api']['props']['yes'] + else + = common.i18n[lang]['docs']['api']['props']['no'] td.desc!= prop.desc[lang] || prop.desc['ja'] diff --git a/src/web/docs/gulpfile.ts b/src/web/docs/gulpfile.ts index 61e44a1dc3..6668abdec6 100644 --- a/src/web/docs/gulpfile.ts +++ b/src/web/docs/gulpfile.ts @@ -37,7 +37,8 @@ gulp.task('doc:docs', () => { const vars = { common: commonVars, lang: lang, - title: fs.readFileSync(file, 'utf-8').match(/^h1 (.+?)\r?\n/)[1] + title: fs.readFileSync(file, 'utf-8').match(/^h1 (.+?)\r?\n/)[1], + src: `https://github.com/syuilo/misskey/tree/master/src/web/docs/${name}.${lang}.pug`, }; pug.renderFile(file, vars, (renderErr, content) => { if (renderErr) { diff --git a/src/web/docs/layout.pug b/src/web/docs/layout.pug index bc9710d7c6..c37967ab82 100644 --- a/src/web/docs/layout.pug +++ b/src/web/docs/layout.pug @@ -27,6 +27,12 @@ html(lang= lang) each endpoint in common.endpoints li: a(href=`./api/endpoints/${common.kebab(endpoint)}`)= endpoint main - block main - if content - | !{content} + article + block main + if content + | !{content} + + footer + p + = common.i18n[lang]['docs']['edit-this-page-on-github'] + a(href=src target="_blank")= common.i18n[lang]['docs']['edit-this-page-on-github-link'] diff --git a/src/web/docs/style.styl b/src/web/docs/style.styl index f222e65bfd..285b92bdb8 100644 --- a/src/web/docs/style.styl +++ b/src/web/docs/style.styl @@ -37,6 +37,14 @@ main margin 1em 0 line-height 1.6em + footer + margin 32px 0 0 0 + border-top solid 2px #eee + + .copyright + margin 16px 0 0 0 + color #aaa + nav display block position fixed @@ -48,15 +56,6 @@ nav padding 32px border-right solid 2px #eee -footer - padding:32px 0 0 0 - margin 32px 0 0 0 - border-top solid 1px #eee - - .copyright - margin 16px 0 0 0 - color #aaa - table width 100% border-spacing 0 diff --git a/src/web/docs/vars.ts b/src/web/docs/vars.ts index ffa262a065..2c744be61b 100644 --- a/src/web/docs/vars.ts +++ b/src/web/docs/vars.ts @@ -1,10 +1,11 @@ import * as fs from 'fs'; import * as glob from 'glob'; import * as yaml from 'js-yaml'; +import langs from '../../../locales'; import config from '../../conf'; -export default function() { - const vars = {}; +export default function(): { [key: string]: any } { + const vars = {} as { [key: string]: any }; const endpoints = glob.sync('./src/web/docs/api/endpoints/**/*.yaml'); vars['endpoints'] = endpoints.map(ep => { @@ -35,5 +36,7 @@ export default function() { vars['config'] = config; + vars['i18n'] = langs; + return vars; } diff --git a/webpack/langs.ts b/webpack/langs.ts deleted file mode 100644 index 409b25504a..0000000000 --- a/webpack/langs.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Languages Loader - */ - -import * as fs from 'fs'; -import * as yaml from 'js-yaml'; - -const loadLang = lang => yaml.safeLoad( - fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')); - -const native = loadLang('ja'); - -const langs = Object.entries({ - 'en': loadLang('en'), - 'ja': native -}); - -langs.map(([, locale]) => { - // Extend native language (Japanese) - locale = Object.assign({}, native, locale); -}); - -export default langs; diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts index 753d89fede..124bd975b9 100644 --- a/webpack/webpack.config.ts +++ b/webpack/webpack.config.ts @@ -5,10 +5,10 @@ import module_ from './module'; import plugins from './plugins'; -import langs from './langs'; +import langs from '../locales'; import version from '../src/version'; -module.exports = langs.map(([lang, locale]) => { +module.exports = Object.entries(langs).map(([lang, locale]) => { // Chunk name const name = lang; -- cgit v1.2.3-freya From d4fb399c95c65e4a6805e02074b8e5cc754a3822 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 17 Dec 2017 14:35:30 +0900 Subject: なんかもうめっちゃ変えた MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gulpfile.ts | 12 ++------ src/common/build/fa.ts | 57 +++++++++++++++++++++++++++++++++++++ src/common/build/i18n.ts | 50 ++++++++++++++++++++++++++++++++ src/web/app/desktop/ui.styl | 2 +- src/web/const.styl | 4 +++ src/web/docs/api.ja.pug | 10 +++---- src/web/docs/api/endpoints/view.pug | 4 +-- src/web/docs/api/entities/view.pug | 2 +- src/web/docs/api/gulpfile.ts | 11 ++++++- src/web/docs/api/mixins.pug | 12 ++++---- src/web/docs/gulpfile.ts | 8 ++++-- src/web/docs/layout.pug | 7 +++-- src/web/docs/style.styl | 1 + src/web/docs/ui.styl | 19 +++++++++++++ src/web/docs/vars.ts | 7 +++-- src/web/style.styl | 5 +--- webpack/module/index.ts | 4 +-- webpack/module/rules/fa.ts | 47 ++---------------------------- webpack/module/rules/i18n.ts | 33 +++------------------ webpack/module/rules/index.ts | 4 +-- webpack/webpack.config.ts | 4 +-- 21 files changed, 185 insertions(+), 118 deletions(-) create mode 100644 src/common/build/fa.ts create mode 100644 src/common/build/i18n.ts create mode 100644 src/web/const.styl create mode 100644 src/web/docs/ui.styl (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/gulpfile.ts b/gulpfile.ts index 3b7a126407..21870473ed 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -20,16 +20,8 @@ import * as mocha from 'gulp-mocha'; import * as replace from 'gulp-replace'; import * as htmlmin from 'gulp-htmlmin'; const uglifyes = require('uglify-es'); -import * as fontawesome from '@fortawesome/fontawesome'; -import * as regular from '@fortawesome/fontawesome-free-regular'; -import * as solid from '@fortawesome/fontawesome-free-solid'; -import * as brands from '@fortawesome/fontawesome-free-brands'; - -// Add icons -fontawesome.library.add(regular); -fontawesome.library.add(solid); -fontawesome.library.add(brands); +import { fa } from './src/common/build/fa'; import version from './src/version'; import config from './src/conf'; @@ -179,7 +171,7 @@ gulp.task('build:client:pug', [ .pipe(pug({ locals: { themeColor: constants.themeColor, - facss: fontawesome.dom.css(), + facss: fa.dom.css(), //hljscss: fs.readFileSync('./node_modules/highlight.js/styles/default.css', 'utf8') hljscss: fs.readFileSync('./src/web/assets/code-highlight.css', 'utf8') } diff --git a/src/common/build/fa.ts b/src/common/build/fa.ts new file mode 100644 index 0000000000..0c21be9504 --- /dev/null +++ b/src/common/build/fa.ts @@ -0,0 +1,57 @@ +/** + * Replace fontawesome symbols + */ + +import * as fontawesome from '@fortawesome/fontawesome'; +import * as regular from '@fortawesome/fontawesome-free-regular'; +import * as solid from '@fortawesome/fontawesome-free-solid'; +import * as brands from '@fortawesome/fontawesome-free-brands'; + +// Add icons +fontawesome.library.add(regular); +fontawesome.library.add(solid); +fontawesome.library.add(brands); + +export const pattern = /%fa:(.+?)%/g; + +export const replacement = (_, key) => { + const args = key.split(' '); + let prefix = 'fas'; + const classes = []; + let transform = ''; + let name; + + args.forEach(arg => { + if (arg == 'R' || arg == 'S' || arg == 'B') { + prefix = + arg == 'R' ? 'far' : + arg == 'S' ? 'fas' : + arg == 'B' ? 'fab' : + ''; + } else if (arg[0] == '.') { + classes.push('fa-' + arg.substr(1)); + } else if (arg[0] == '-') { + transform = arg.substr(1).split('|').join(' '); + } else { + name = arg; + } + }); + + const icon = fontawesome.icon({ prefix, iconName: name }, { + classes: classes + }); + + if (icon) { + icon.transform = fontawesome.parse.transform(transform); + return `${icon.html[0]}`; + } else { + console.warn(`'${name}' not found in fa`); + return ''; + } +}; + +export default (src: string) => { + return src.replace(pattern, replacement); +}; + +export const fa = fontawesome; diff --git a/src/common/build/i18n.ts b/src/common/build/i18n.ts new file mode 100644 index 0000000000..1ae22147c4 --- /dev/null +++ b/src/common/build/i18n.ts @@ -0,0 +1,50 @@ +/** + * Replace i18n texts + */ + +import locale from '../../../locales'; + +export default class Replacer { + private lang: string; + + public pattern = /"%i18n:(.+?)%"|'%i18n:(.+?)%'|%i18n:(.+?)%/g; + + constructor(lang: string) { + this.lang = lang; + + this.get = this.get.bind(this); + this.replacement = this.replacement.bind(this); + } + + private get(key: string) { + let text = locale[this.lang]; + + // Check the key existance + const error = key.split('.').some(k => { + if (text.hasOwnProperty(k)) { + text = text[k]; + return false; + } else { + return true; + } + }); + + if (error) { + console.warn(`key '${key}' not found in '${this.lang}'`); + return key; // Fallback + } else { + return text; + } + } + + public replacement(match, a, b, c) { + const key = a || b || c; + if (match[0] == '"') { + return '"' + this.get(key).replace(/"/g, '\\"') + '"'; + } else if (match[0] == "'") { + return '\'' + this.get(key).replace(/'/g, '\\\'') + '\''; + } else { + return this.get(key); + } + } +} diff --git a/src/web/app/desktop/ui.styl b/src/web/app/desktop/ui.styl index cb98bf06a0..058271876b 100644 --- a/src/web/app/desktop/ui.styl +++ b/src/web/app/desktop/ui.styl @@ -1,4 +1,4 @@ -@import "../app" +@import "../../const" button font-family sans-serif diff --git a/src/web/const.styl b/src/web/const.styl new file mode 100644 index 0000000000..b6560701d9 --- /dev/null +++ b/src/web/const.styl @@ -0,0 +1,4 @@ +json('../const.json') + +$theme-color = themeColor +$theme-color-foreground = themeColorForeground diff --git a/src/web/docs/api.ja.pug b/src/web/docs/api.ja.pug index 5514a40975..2584b08581 100644 --- a/src/web/docs/api.ja.pug +++ b/src/web/docs/api.ja.pug @@ -7,6 +7,7 @@ section h2 自分の所有するアカウントからAPIにアクセスする場合 p 「設定 > API」で、APIにアクセスするのに必要なAPIキーを取得してください。 p APIにアクセスする際には、リクエストにAPIキーを「i」というパラメータ名で含めます。 + div.ui.info.warn: p %fa:exclamation-triangle%アカウントを不正利用される可能性があるため、このトークンは第三者に教えないでください(アプリなどにも入力しないでください)。 p APIの詳しい使用法は「Misskey APIの利用」セクションをご覧ください。 section @@ -15,7 +16,7 @@ section | 直接ユーザーのAPIキーをアプリケーションが扱うのは危険なので、 | アプリケーションからAPIを利用する際には、アプリケーションとアプリケーションを利用するユーザーが結び付けられた専用のトークン(アクセストークン)をMisskeyに発行してもらい、 | そのトークンをリクエストのパラメータに含める必要があります。 - | (アクセストークンは、ユーザーが自分のアカウントにあなたのアプリケーションがアクセスすることを許可した場合のみ発行されます) + div.ui.info: p %fa:info-circle%アクセストークンは、ユーザーが自分のアカウントにあなたのアプリケーションがアクセスすることを許可した場合のみ発行されます p それでは、アクセストークンを取得するまでの流れを説明します。 @@ -46,9 +47,8 @@ section td 権限 td あなたのアプリケーションやWebサービスが要求する権限。ここで要求した機能だけがAPIからアクセスできます。 - p - | 登録が済むとアプリケーションのシークレットキーが入手できます。このシークレットキーは後で使用します。 - | アプリに成りすまされる可能性があるため、極力このシークレットキーは公開しないようにしてください。 + p 登録が済むとアプリケーションのシークレットキーが入手できます。このシークレットキーは後で使用します。 + div.ui.info.warn: p %fa:exclamation-triangle%アプリに成りすまされる可能性があるため、極力このシークレットキーは公開しないようにしてください。 section h3 2.ユーザーに認証させる @@ -93,7 +93,7 @@ section h2 Misskey APIの利用 p APIはすべてリクエストのパラメータ・レスポンスともにJSON形式です。また、すべてのエンドポイントはPOSTメソッドのみ受け付けます。 p APIリファレンスもご確認ください。 - + section h3 レートリミット p Misskey APIにはレートリミットがあり、短時間のうちに多数のリクエストを送信すると、一定時間APIを利用することができなくなることがあります。 diff --git a/src/web/docs/api/endpoints/view.pug b/src/web/docs/api/endpoints/view.pug index 90084ab276..d271a5517a 100644 --- a/src/web/docs/api/endpoints/view.pug +++ b/src/web/docs/api/endpoints/view.pug @@ -17,7 +17,7 @@ block main p#desc= desc[lang] || desc['ja'] section - h2= common.i18n[lang]['docs']['api']['endpoints']['params'] + h2 %i18n:docs.api.endpoints.params% +propTable(params) if paramDefs @@ -28,5 +28,5 @@ block main if res section - h2= common.i18n[lang]['docs']['api']['endpoints']['res'] + h2 %i18n:docs.api.endpoints.res% +propTable(res) diff --git a/src/web/docs/api/entities/view.pug b/src/web/docs/api/entities/view.pug index 99e786c694..2156463dc7 100644 --- a/src/web/docs/api/entities/view.pug +++ b/src/web/docs/api/entities/view.pug @@ -10,7 +10,7 @@ block main p#desc= desc[lang] || desc['ja'] section - h2= common.i18n[lang]['docs']['api']['entities']['properties'] + h2 %i18n:docs.api.entities.properties% +propTable(props) if propDefs diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 2e8409c595..4c30871a0f 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -10,13 +10,16 @@ import * as pug from 'pug'; import * as yaml from 'js-yaml'; import * as mkdirp from 'mkdirp'; +import locales from '../../../../locales'; +import I18nReplacer from '../../../common/build/i18n'; +import fa from '../../../common/build/fa'; import config from './../../../conf'; import generateVars from '../vars'; const commonVars = generateVars(); -const langs = Object.keys(commonVars.i18n); +const langs = Object.keys(locales); const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); @@ -124,6 +127,9 @@ gulp.task('doc:api:endpoints', () => { console.error(renderErr); return; } + const i18n = new I18nReplacer(lang); + html = html.replace(i18n.pattern, i18n.replacement); + html = fa(html); const htmlPath = `./built/web/docs/${lang}/api/endpoints/${ep.endpoint}.html`; mkdirp(path.dirname(htmlPath), (mkdirErr) => { if (mkdirErr) { @@ -164,6 +170,9 @@ gulp.task('doc:api:entities', () => { console.error(renderErr); return; } + const i18n = new I18nReplacer(lang); + html = html.replace(i18n.pattern, i18n.replacement); + html = fa(html); const htmlPath = `./built/web/docs/${lang}/api/entities/${kebab(entity.name)}.html`; mkdirp(path.dirname(htmlPath), (mkdirErr) => { if (mkdirErr) { diff --git a/src/web/docs/api/mixins.pug b/src/web/docs/api/mixins.pug index b563a121db..686bf6a2b6 100644 --- a/src/web/docs/api/mixins.pug +++ b/src/web/docs/api/mixins.pug @@ -1,10 +1,10 @@ mixin propTable(props) table.props thead: tr - th= common.i18n[lang]['docs']['api']['props']['name'] - th= common.i18n[lang]['docs']['api']['props']['type'] - th= common.i18n[lang]['docs']['api']['props']['optional'] - th= common.i18n[lang]['docs']['api']['props']['description'] + th %i18n:docs.api.props.name% + th %i18n:docs.api.props.type% + th %i18n:docs.api.props.optional% + th %i18n:docs.api.props.description% tbody each prop in props tr @@ -31,7 +31,7 @@ mixin propTable(props) | (Date) td.optional if prop.optional - = common.i18n[lang]['docs']['api']['props']['yes'] + | %i18n:docs.api.props.yes% else - = common.i18n[lang]['docs']['api']['props']['no'] + | %i18n:docs.api.props.no% td.desc!= prop.desc[lang] || prop.desc['ja'] diff --git a/src/web/docs/gulpfile.ts b/src/web/docs/gulpfile.ts index 6668abdec6..71033e1bc7 100644 --- a/src/web/docs/gulpfile.ts +++ b/src/web/docs/gulpfile.ts @@ -7,13 +7,12 @@ import * as path from 'path'; import * as glob from 'glob'; import * as gulp from 'gulp'; import * as pug from 'pug'; -//import * as yaml from 'js-yaml'; import * as mkdirp from 'mkdirp'; import stylus = require('gulp-stylus'); import cssnano = require('gulp-cssnano'); -//import config from './../../conf'; - +import I18nReplacer from '../../common/build/i18n'; +import fa from '../../common/build/fa'; import generateVars from './vars'; require('./api/gulpfile.ts'); @@ -53,6 +52,9 @@ gulp.task('doc:docs', () => { console.error(renderErr2); return; } + const i18n = new I18nReplacer(lang); + html = html.replace(i18n.pattern, i18n.replacement); + html = fa(html); const htmlPath = `./built/web/docs/${lang}/${name}.html`; mkdirp(path.dirname(htmlPath), (mkdirErr) => { if (mkdirErr) { diff --git a/src/web/docs/layout.pug b/src/web/docs/layout.pug index ee8018ec63..9dfd0ab7af 100644 --- a/src/web/docs/layout.pug +++ b/src/web/docs/layout.pug @@ -9,6 +9,9 @@ html(lang= lang) link(rel="stylesheet" href="/assets/style.css") block meta + //- FontAwesome style + style #{common.facss} + body nav ul @@ -33,6 +36,6 @@ html(lang= lang) footer p - = common.i18n[lang]['docs']['edit-this-page-on-github'] - a(href=src target="_blank")= common.i18n[lang]['docs']['edit-this-page-on-github-link'] + | %i18n:docs.edit-this-page-on-github% + a(href=src target="_blank") %i18n:docs.edit-this-page-on-github-link% small= common.copyright diff --git a/src/web/docs/style.styl b/src/web/docs/style.styl index 32a2264f15..414be5c53d 100644 --- a/src/web/docs/style.styl +++ b/src/web/docs/style.styl @@ -1,4 +1,5 @@ @import "../style" +@import "./ui" body margin 0 diff --git a/src/web/docs/ui.styl b/src/web/docs/ui.styl new file mode 100644 index 0000000000..8d5515712f --- /dev/null +++ b/src/web/docs/ui.styl @@ -0,0 +1,19 @@ +.ui.info + display block + margin 1em 0 + padding 0 1em + font-size 90% + color rgba(#000, 0.87) + background #f8f8f9 + border-radius 4px + overflow hidden + + > p + opacity 0.8 + + > [data-fa]:first-child + margin-right 0.25em + + &.warn + color #573a08 + background #FFFAF3 diff --git a/src/web/docs/vars.ts b/src/web/docs/vars.ts index da590d7bd9..65b224fbff 100644 --- a/src/web/docs/vars.ts +++ b/src/web/docs/vars.ts @@ -1,7 +1,8 @@ import * as fs from 'fs'; import * as glob from 'glob'; import * as yaml from 'js-yaml'; -import langs from '../../../locales'; + +import { fa } from '../../common/build/fa'; import config from '../../conf'; const constants = require('../../const.json'); @@ -37,9 +38,9 @@ export default function(): { [key: string]: any } { vars['config'] = config; - vars['i18n'] = langs; - vars['copyright'] = constants.copyright; + vars['facss'] = fa.dom.css(); + return vars; } diff --git a/src/web/style.styl b/src/web/style.styl index 573df10d78..c25fc8fb52 100644 --- a/src/web/style.styl +++ b/src/web/style.styl @@ -1,9 +1,6 @@ -json('../const.json') - @charset 'utf-8' -$theme-color = themeColor -$theme-color-foreground = themeColorForeground +@import "./const" /* ::selection diff --git a/webpack/module/index.ts b/webpack/module/index.ts index 15f36557ce..088aca7238 100644 --- a/webpack/module/index.ts +++ b/webpack/module/index.ts @@ -1,5 +1,5 @@ import rules from './rules'; -export default (lang, locale) => ({ - rules: rules(lang, locale) +export default lang => ({ + rules: rules(lang) }); diff --git a/webpack/module/rules/fa.ts b/webpack/module/rules/fa.ts index 47c72a28a1..891b78ece2 100644 --- a/webpack/module/rules/fa.ts +++ b/webpack/module/rules/fa.ts @@ -3,16 +3,7 @@ */ const StringReplacePlugin = require('string-replace-webpack-plugin'); - -import * as fontawesome from '@fortawesome/fontawesome'; -import * as regular from '@fortawesome/fontawesome-free-regular'; -import * as solid from '@fortawesome/fontawesome-free-solid'; -import * as brands from '@fortawesome/fontawesome-free-brands'; - -// Add icons -fontawesome.library.add(regular); -fontawesome.library.add(solid); -fontawesome.library.add(brands); +import { pattern, replacement } from '../../../src/common/build/fa'; export default () => ({ enforce: 'pre', @@ -20,41 +11,7 @@ export default () => ({ exclude: /node_modules/, loader: StringReplacePlugin.replace({ replacements: [{ - pattern: /%fa:(.+?)%/g, replacement: (_, key) => { - const args = key.split(' '); - let prefix = 'fas'; - const classes = []; - let transform = ''; - let name; - - args.forEach(arg => { - if (arg == 'R' || arg == 'S' || arg == 'B') { - prefix = - arg == 'R' ? 'far' : - arg == 'S' ? 'fas' : - arg == 'B' ? 'fab' : - ''; - } else if (arg[0] == '.') { - classes.push('fa-' + arg.substr(1)); - } else if (arg[0] == '-') { - transform = arg.substr(1).split('|').join(' '); - } else { - name = arg; - } - }); - - const icon = fontawesome.icon({ prefix, iconName: name }, { - classes: classes - }); - - if (icon) { - icon.transform = fontawesome.parse.transform(transform); - return `${icon.html[0]}`; - } else { - console.warn(`'${name}' not found in fa`); - return ''; - } - } + pattern, replacement }] }) }); diff --git a/webpack/module/rules/i18n.ts b/webpack/module/rules/i18n.ts index aa4e58448f..7261548be5 100644 --- a/webpack/module/rules/i18n.ts +++ b/webpack/module/rules/i18n.ts @@ -3,28 +3,10 @@ */ const StringReplacePlugin = require('string-replace-webpack-plugin'); +import Replacer from '../../../src/common/build/i18n'; -export default (lang, locale) => { - function get(key: string) { - let text = locale; - - // Check the key existance - const error = key.split('.').some(k => { - if (text.hasOwnProperty(k)) { - text = text[k]; - return false; - } else { - return true; - } - }); - - if (error) { - console.warn(`key '${key}' not found in '${lang}'`); - return key; // Fallback - } else { - return text; - } - } +export default lang => { + const replacer = new Replacer(lang); return { enforce: 'pre', @@ -32,14 +14,7 @@ export default (lang, locale) => { exclude: /node_modules/, loader: StringReplacePlugin.replace({ replacements: [{ - pattern: /"%i18n:(.+?)%"/g, replacement: (_, key) => - '"' + get(key).replace(/"/g, '\\"') + '"' - }, { - pattern: /'%i18n:(.+?)%'/g, replacement: (_, key) => - '\'' + get(key).replace(/'/g, '\\\'') + '\'' - }, { - pattern: /%i18n:(.+?)%/g, replacement: (_, key) => - get(key) + pattern: replacer.pattern, replacement: replacer.replacement }] }) }; diff --git a/webpack/module/rules/index.ts b/webpack/module/rules/index.ts index b6a0a5e2ec..b02bdef723 100644 --- a/webpack/module/rules/index.ts +++ b/webpack/module/rules/index.ts @@ -7,8 +7,8 @@ import tag from './tag'; import stylus from './stylus'; import typescript from './typescript'; -export default (lang, locale) => [ - i18n(lang, locale), +export default lang => [ + i18n(lang), license(), fa(), base64(), diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts index 124bd975b9..d67b8ef774 100644 --- a/webpack/webpack.config.ts +++ b/webpack/webpack.config.ts @@ -8,7 +8,7 @@ import plugins from './plugins'; import langs from '../locales'; import version from '../src/version'; -module.exports = Object.entries(langs).map(([lang, locale]) => { +module.exports = Object.keys(langs).map(lang => { // Chunk name const name = lang; @@ -32,7 +32,7 @@ module.exports = Object.entries(langs).map(([lang, locale]) => { return { name, entry, - module: module_(lang, locale), + module: module_(lang), plugins: plugins(version, lang), output, resolve: { -- cgit v1.2.3-freya From 6b9f6c6e3b2f82ea2a466614626b7bfaa6ad9286 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 8 Jan 2018 01:47:56 +0900 Subject: Show the licenses in the doc --- package.json | 2 ++ src/web/docs/api/gulpfile.ts | 8 ++++---- src/web/docs/gulpfile.ts | 4 ++-- src/web/docs/license.en.pug | 14 ++++++++++++++ src/web/docs/license.ja.pug | 14 ++++++++++++++ src/web/docs/style.styl | 2 ++ src/web/docs/vars.ts | 17 ++++++++++++++++- 7 files changed, 54 insertions(+), 7 deletions(-) (limited to 'src/web/docs/api/gulpfile.ts') diff --git a/package.json b/package.json index 9245a6e2a1..69c92efdfd 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@types/is-root": "1.0.0", "@types/is-url": "1.2.28", "@types/js-yaml": "3.10.1", + "@types/license-checker": "^15.0.0", "@types/mkdirp": "0.5.2", "@types/mocha": "2.2.45", "@types/mongodb": "2.2.18", @@ -122,6 +123,7 @@ "is-root": "1.0.0", "is-url": "1.2.2", "js-yaml": "3.10.0", + "license-checker": "^15.0.0", "mecab-async": "0.1.2", "mkdirp": "0.5.1", "mocha": "4.1.0", diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts index 4c30871a0f..cd1bf15307 100644 --- a/src/web/docs/api/gulpfile.ts +++ b/src/web/docs/api/gulpfile.ts @@ -17,8 +17,6 @@ import config from './../../../conf'; import generateVars from '../vars'; -const commonVars = generateVars(); - const langs = Object.keys(locales); const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); @@ -94,7 +92,8 @@ gulp.task('doc:api', [ 'doc:api:entities' ]); -gulp.task('doc:api:endpoints', () => { +gulp.task('doc:api:endpoints', async () => { + const commonVars = await generateVars(); glob('./src/web/docs/api/endpoints/**/*.yaml', (globErr, files) => { if (globErr) { console.error(globErr); @@ -144,7 +143,8 @@ gulp.task('doc:api:endpoints', () => { }); }); -gulp.task('doc:api:entities', () => { +gulp.task('doc:api:entities', async () => { + const commonVars = await generateVars(); glob('./src/web/docs/api/entities/**/*.yaml', (globErr, files) => { if (globErr) { console.error(globErr); diff --git a/src/web/docs/gulpfile.ts b/src/web/docs/gulpfile.ts index 71033e1bc7..d5ddda108d 100644 --- a/src/web/docs/gulpfile.ts +++ b/src/web/docs/gulpfile.ts @@ -23,9 +23,9 @@ gulp.task('doc', [ 'doc:styles' ]); -const commonVars = generateVars(); +gulp.task('doc:docs', async () => { + const commonVars = await generateVars(); -gulp.task('doc:docs', () => { glob('./src/web/docs/**/*.*.pug', (globErr, files) => { if (globErr) { console.error(globErr); diff --git a/src/web/docs/license.en.pug b/src/web/docs/license.en.pug index 240756e7ea..45d8b76473 100644 --- a/src/web/docs/license.en.pug +++ b/src/web/docs/license.en.pug @@ -1,3 +1,17 @@ h1 License div!= common.license + +details + summary Libraries + + section + h2 Libraries + + each dependency, name in common.dependencies + details + summary= name + + section + h3= name + pre= dependency.licenseText diff --git a/src/web/docs/license.ja.pug b/src/web/docs/license.ja.pug index 1f44f3f5e7..7bd9a62941 100644 --- a/src/web/docs/license.ja.pug +++ b/src/web/docs/license.ja.pug @@ -1,3 +1,17 @@ h1 ライセンス div!= common.license + +details + summary ライブラリ + + section + h2 ライブラリ + + each dependency, name in common.dependencies + details + summary= name + + section + h3= name + pre= dependency.licenseText diff --git a/src/web/docs/style.styl b/src/web/docs/style.styl index a726d49b16..bc165f8728 100644 --- a/src/web/docs/style.styl +++ b/src/web/docs/style.styl @@ -114,5 +114,7 @@ code border-radius 4px pre + overflow auto + > code display block diff --git a/src/web/docs/vars.ts b/src/web/docs/vars.ts index 95ae9ee629..6f713f21d0 100644 --- a/src/web/docs/vars.ts +++ b/src/web/docs/vars.ts @@ -1,13 +1,16 @@ import * as fs from 'fs'; +import * as util from 'util'; import * as glob from 'glob'; import * as yaml from 'js-yaml'; +import * as licenseChecker from 'license-checker'; +import * as tmp from 'tmp'; import { fa } from '../../common/build/fa'; import config from '../../conf'; import { licenseHtml } from '../../common/build/license'; const constants = require('../../const.json'); -export default function(): { [key: string]: any } { +export default async function(): Promise<{ [key: string]: any }> { const vars = {} as { [key: string]: any }; const endpoints = glob.sync('./src/web/docs/api/endpoints/**/*.yaml'); @@ -45,5 +48,17 @@ export default function(): { [key: string]: any } { vars['license'] = licenseHtml; + const tmpObj = tmp.fileSync(); + fs.writeFileSync(tmpObj.name, JSON.stringify({ + licenseText: '' + }), 'utf-8'); + const dependencies = await util.promisify(licenseChecker.init).bind(licenseChecker)({ + start: __dirname + '/../../../', + customPath: tmpObj.name + }); + tmpObj.removeCallback(); + + vars['dependencies'] = dependencies; + return vars; } -- cgit v1.2.3-freya