From 2453b2a9be16aeb379d62e31db02d43b60b5f8f7 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 18:29:37 +0800 Subject: [PATCH 001/204] set lang attr on according to user's choice Signed-off-by: BinotaLIU --- public/views/codimd.ejs | 2 +- public/views/error.ejs | 2 +- public/views/index.ejs | 2 +- public/views/pretty.ejs | 2 +- public/views/slide.ejs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/public/views/codimd.ejs b/public/views/codimd.ejs index 7818346c39..33341b4a35 100644 --- a/public/views/codimd.ejs +++ b/public/views/codimd.ejs @@ -1,5 +1,5 @@ - + <%- include codimd/head %> diff --git a/public/views/error.ejs b/public/views/error.ejs index 3ed76c8ce5..874988a5ed 100644 --- a/public/views/error.ejs +++ b/public/views/error.ejs @@ -1,5 +1,5 @@ - + <%- include codimd/head %> diff --git a/public/views/index.ejs b/public/views/index.ejs index 5732db4a3c..b7a3f6846d 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -1,5 +1,5 @@ - + <%- include index/head %> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index aa330e0f32..6d780c7371 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -1,5 +1,5 @@ - + diff --git a/public/views/slide.ejs b/public/views/slide.ejs index 42b1165d49..295b75f598 100644 --- a/public/views/slide.ejs +++ b/public/views/slide.ejs @@ -1,5 +1,5 @@ - + From bdd2de72bafaa6f67bb4cd7a6cfba803b55ee817 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 19:26:06 +0800 Subject: [PATCH 002/204] set default lang attr for note to 'en' Signed-off-by: BinotaLIU --- public/js/extra.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 99233c097b..8f38a96e2f 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -191,18 +191,15 @@ export function parseMeta (md, edit, view, toc, tocAffix) { dir = meta.dir breaks = meta.breaks } - // text language - if (lang && typeof lang === 'string') { - view.attr('lang', lang) - toc.attr('lang', lang) - tocAffix.attr('lang', lang) - if (edit) { edit.attr('lang', lang) } - } else { - view.removeAttr('lang') - toc.removeAttr('lang') - tocAffix.removeAttr('lang') - if (edit) { edit.removeAttr('lang', lang) } + if (!lang || typeof lang !== 'string') { + lang = 'en' } + // text language + view.attr('lang', lang) + toc.attr('lang', lang) + tocAffix.attr('lang', lang) + if (edit) { edit.attr('lang', lang) } + // text direction if (dir && typeof dir === 'string') { view.attr('dir', dir) From 9b899c7778c7f5e066f031640ff3dfc563964623 Mon Sep 17 00:00:00 2001 From: BinotaLIU Date: Fri, 10 Apr 2020 22:40:28 +0800 Subject: [PATCH 003/204] escape attribute value for lang Signed-off-by: BinotaLIU --- public/js/extra.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 8f38a96e2f..61007b8b60 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -16,6 +16,8 @@ import { stripTags } from '../../utils/string' import getUIElements from './lib/editor/ui-elements' import { emojifyImageDir } from './lib/editor/constants' +import { escapeAttrValue } from './render' + import markdownit from 'markdown-it' import markdownitContainer from 'markdown-it-container' @@ -734,8 +736,8 @@ export function exportToHTML (view) { html: src[0].outerHTML, 'ui-toc': toc.html(), 'ui-toc-affix': tocAffix.html(), - lang: (md && md.meta && md.meta.lang) ? `lang="${md.meta.lang}"` : null, - dir: (md && md.meta && md.meta.dir) ? `dir="${md.meta.dir}"` : null + lang: (md && md.meta && md.meta.lang) ? `lang="${escapeAttrValue(md.meta.lang)}"` : null, + dir: (md && md.meta && md.meta.dir) ? `dir="${escapeAttrValue(md.meta.dir)}"` : null } const html = template(context) // console.log(html); From 5847bf09bfabd1027e7ba93c5bfed53b58be434d Mon Sep 17 00:00:00 2001 From: Gereon Dusella Date: Mon, 1 Jun 2020 22:27:16 +0200 Subject: [PATCH 004/204] added an option to set the depth of the table of contents freely for every note Signed-off-by: Gereon Dusella --- public/css/extra.css | 60 ++++++++++++++++++++++++++++++++++++ public/docs/yaml-metadata.md | 16 ++++++++++ public/js/extra.js | 12 ++++++-- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/public/css/extra.css b/public/css/extra.css index 2b23ad2413..f46eb3e6dc 100644 --- a/public/css/extra.css +++ b/public/css/extra.css @@ -253,6 +253,32 @@ padding-right: 40px; } +.ui-toc-dropdown .nav .nav>li>ul>li>ul>li>a { + padding-top: 1px; + padding-bottom: 1px; + padding-left: 50px; + font-size: 12px; + font-weight: 400; +} + +.ui-toc-dropdown[dir='rtl'] .nav .nav>li>ul>li>ul>li>a { + padding-right: 50px; +} + +.ui-toc-dropdown .nav .nav>li>ul>li>ul>li>ul>li>a { + padding-top: 1px; + padding-bottom: 1px; + padding-left: 60px; + font-size: 12px; + font-weight: 400; +} + +.ui-toc-dropdown[dir='rtl'] .nav .nav>li>ul>li>ul>li>ul>li>a { + padding-right: 60px; +} + + + .ui-toc-dropdown .nav .nav>li>a:focus,.ui-toc-dropdown .nav .nav>li>a:hover { padding-left: 29px; } @@ -269,6 +295,22 @@ padding-right: 39px; } +.ui-toc-dropdown .nav .nav>li>ul>li>ul>li>a:focus,.ui-toc-dropdown .nav .nav>li>ul>li>ul>li>a:hover { + padding-left: 49px; +} + +.ui-toc-dropdown[dir='rtl'] .nav .nav>li>ul>li>ul>li>a:focus,.ui-toc-dropdown[dir='rtl'] .nav .nav>li>ul>li>ul>li>a:hover { + padding-right: 49px; +} + +.ui-toc-dropdown .nav .nav>li>ul>li>ul>li>ul>li>a:focus,.ui-toc-dropdown .nav .nav>li>ul>li>ul>li>ul>li>a:hover { + padding-left: 59px; +} + +.ui-toc-dropdown[dir='rtl'] .nav .nav>li>ul>li>ul>li>ul>li>a:focus,.ui-toc-dropdown[dir='rtl'] .nav .nav>li>ul>li>ul>li>ul>li>a:hover { + padding-right: 59px; +} + .ui-toc-dropdown .nav .nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>a { padding-left: 28px; font-weight: 500; @@ -287,6 +329,24 @@ padding-right: 38px; } +.ui-toc-dropdown .nav .nav>.active>.nav>.active>.nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>.nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>.nav>.active>a { + padding-left: 48px; + font-weight: 500; +} + +.ui-toc-dropdown[dir='rtl'] .nav .nav>.active>.nav>.active>.nav>.active:focus>a,.ui-toc-dropdown[dir='rtl'] .nav .nav>.active>.nav>.active>.nav>.active:hover>a,.ui-toc-dropdown[dir='rtl'] .nav .nav>.active>.active>.nav>.nav>.active>a { + padding-right: 48px; +} + +.ui-toc-dropdown .nav .nav>.active>.nav>.active>.nav>.active>.nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>.nav>.active>.nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>.nav>.active>.nav>.active>a { + padding-left: 58px; + font-weight: 500; +} + +.ui-toc-dropdown[dir='rtl'] .nav .nav>.active>.nav>.active>.nav>.active>.nav>.active:focus>a,.ui-toc-dropdown[dir='rtl'] .nav .nav>.active>.nav>.active>.nav>.active>.nav>.active:hover>a,.ui-toc-dropdown[dir='rtl'] .nav .nav>.active>.active>.nav>.nav>.active>.nav>.active>a { + padding-right: 58px; +} + /* support japanese font */ .markdown-body[lang^="ja"] { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, "Hiragino Kaku Gothic Pro", "ヒラギノ角ゴ Pro W3", Osaka, Meiryo, "メイリオ", "MS Gothic", "MS ゴシック", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; diff --git a/public/docs/yaml-metadata.md b/public/docs/yaml-metadata.md index 839616a8f9..48bc06ea43 100644 --- a/public/docs/yaml-metadata.md +++ b/public/docs/yaml-metadata.md @@ -128,6 +128,22 @@ This option allows you to enable Disqus with your shortname. disqus: codimd ``` +toc +--- + +This option allows you to set options regarding the table of contents (toc). Currently, its only option is to set the maxDepth. + +**Notice: always use two spaces as indention in YAML metadata!** + + +> **maxDepth:** +> default: not set (whioch will show everything until level 3 (h1 -- h3)) +> max: 5 (as defined by doctoc) + + +**Example** + + type --- This option allows you to switch the document view to the slide preview, to simplify live editing of presentations. diff --git a/public/js/extra.js b/public/js/extra.js index dfc206b0aa..b203280e41 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -811,8 +811,12 @@ export function generateToc (id) { const target = $(`#${id}`) target.html('') /* eslint-disable no-unused-vars */ + + var tocOptions = md.meta.toc || {} + var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : 3 + var toc = new window.Toc('doc', { - level: 3, + level: maxLevel, top: -1, class: 'toc', ulClass: 'nav', @@ -1010,8 +1014,12 @@ export function renderTOC (view) { const target = $(`#${id}`) target.html('') /* eslint-disable no-unused-vars */ + + var tocOptions = md.meta.toc || {} + var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : 3 + const TOC = new window.Toc('doc', { - level: 3, + level: maxLevel, top: -1, class: 'toc', targetId: id, From 56e01fa76e3ac2a82577d9bf47cbe65013f84ff6 Mon Sep 17 00:00:00 2001 From: Gereon Dusella Date: Wed, 3 Jun 2020 17:38:28 +0200 Subject: [PATCH 005/204] added an Environment Variable `CMD_DEFAULT_TOC_DEPTH` to set default toc depth Signed-off-by: Gereon Dusella --- lib/config/default.js | 3 ++- lib/config/environment.js | 3 ++- lib/status/index.js | 3 ++- public/js/extra.js | 4 ++-- public/js/lib/common/constant.ejs | 2 ++ 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/config/default.js b/lib/config/default.js index 95ee1940fe..08a4413d05 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -188,5 +188,6 @@ module.exports = { // 2nd appearance: "31-good-morning-my-friend---do-you-have-5-1" // 3rd appearance: "31-good-morning-my-friend---do-you-have-5-2" linkifyHeaderStyle: 'keep-case', - autoVersionCheck: true + autoVersionCheck: true, + defaultTocDepth: 3 } diff --git a/lib/config/environment.js b/lib/config/environment.js index 0867aecf54..cbf0f4c13f 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -147,5 +147,6 @@ module.exports = { openID: toBooleanConfig(process.env.CMD_OPENID), defaultUseHardbreak: toBooleanConfig(process.env.CMD_DEFAULT_USE_HARD_BREAK), linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE, - autoVersionCheck: toBooleanConfig(process.env.CMD_AUTO_VERSION_CHECK) + autoVersionCheck: toBooleanConfig(process.env.CMD_AUTO_VERSION_CHECK), + defaultTocDepth: toIntegerConfig(process.env.CMD_DEFAULT_TOC_DEPTH) } diff --git a/lib/status/index.js b/lib/status/index.js index 2f5366d62c..2e344efa2f 100644 --- a/lib/status/index.js +++ b/lib/status/index.js @@ -41,7 +41,8 @@ exports.getConfig = (req, res) => { allowedUploadMimeTypes: config.allowedUploadMimeTypes, defaultUseHardbreak: config.defaultUseHardbreak, linkifyHeaderStyle: config.linkifyHeaderStyle, - useCDN: config.useCDN + useCDN: config.useCDN, + defaultTocDepth: config.defaultTocDepth } res.set({ 'Cache-Control': 'private', // only cache by client diff --git a/public/js/extra.js b/public/js/extra.js index b203280e41..9adab00094 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -813,7 +813,7 @@ export function generateToc (id) { /* eslint-disable no-unused-vars */ var tocOptions = md.meta.toc || {} - var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : 3 + var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : window.defaultTocDepth var toc = new window.Toc('doc', { level: maxLevel, @@ -1016,7 +1016,7 @@ export function renderTOC (view) { /* eslint-disable no-unused-vars */ var tocOptions = md.meta.toc || {} - var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : 3 + var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : window.defaultTocDepth const TOC = new window.Toc('doc', { level: maxLevel, diff --git a/public/js/lib/common/constant.ejs b/public/js/lib/common/constant.ejs index 57438912a7..3cb960ff2f 100644 --- a/public/js/lib/common/constant.ejs +++ b/public/js/lib/common/constant.ejs @@ -13,3 +13,5 @@ window.linkifyHeaderStyle = '<%- linkifyHeaderStyle %>' window.DROPBOX_APP_KEY = '<%- DROPBOX_APP_KEY %>' window.USE_CDN = <%- useCDN %> + +window.defaultTocDepth = <%- defaultTocDepth %> From b15c59e15e151d484b5021f14b50b83729ea54c1 Mon Sep 17 00:00:00 2001 From: Gereon Dusella Date: Wed, 3 Jun 2020 18:32:48 +0200 Subject: [PATCH 006/204] added an option to set the TOC depth directly inside the [toc] tag Signed-off-by: Gereon Dusella --- public/js/extra.js | 14 +++++++++++--- public/vendor/md-toc.js | 6 ++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/public/js/extra.js b/public/js/extra.js index 9adab00094..8384739ad8 100644 --- a/public/js/extra.js +++ b/public/js/extra.js @@ -1015,14 +1015,19 @@ export function renderTOC (view) { target.html('') /* eslint-disable no-unused-vars */ + const specificDepth = parseInt(toc.data('toc-depth')) + var tocOptions = md.meta.toc || {} - var maxLevel = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : window.defaultTocDepth + var yamlMaxDepth = (typeof tocOptions.maxLevel === 'number' && tocOptions.maxLevel > 0) ? tocOptions.maxLevel : window.defaultTocDepth + + var maxLevel = specificDepth || yamlMaxDepth const TOC = new window.Toc('doc', { level: maxLevel, top: -1, class: 'toc', targetId: id, + data: { tocDepth: specificDepth }, process: getHeaderContent }) /* eslint-enable no-unused-vars */ @@ -1268,9 +1273,12 @@ const gistPlugin = new Plugin( // TOC const tocPlugin = new Plugin( // regexp to match - /^\[TOC\]$/i, + /^\[TOC(|\s*maxLevel=\d+?)\]$/i, - (match, utils) => '
' + (match, utils) => { + const tocDepth = match[1].split(/[?&=]+/)[1] + return `
` + } ) // slideshare const slidesharePlugin = new Plugin( diff --git a/public/vendor/md-toc.js b/public/vendor/md-toc.js index 59e75aed3a..0c7b511641 100644 --- a/public/vendor/md-toc.js +++ b/public/vendor/md-toc.js @@ -2,6 +2,8 @@ /** * md-toc.js v1.0.2 * https://github.com/yijian166/md-toc.js + * + * Adapted to accept data attributes */ (function (window) { @@ -15,6 +17,7 @@ this.tocTop = parseInt(options.top) || 0 this.elChilds = this.el.children this.process = options['process'] + this.data = options.data || {} if (!this.elChilds.length) return this._init() } @@ -123,6 +126,9 @@ this.toc = document.createElement('div') this.toc.innerHTML = this.tocContent this.toc.setAttribute('class', this.tocClass) + if (this.data.tocDepth) { + this.toc.dataset.tocDepth = this.data.tocDepth + } if (!this.options.targetId) { this.el.appendChild(this.toc) } else { From aa7fb0e0128480d80d4b037794374f459f443ee1 Mon Sep 17 00:00:00 2001 From: Gereon Dusella Date: Wed, 3 Jun 2020 18:41:41 +0200 Subject: [PATCH 007/204] wrong package referenced in public/docs/yaml-metadata.md Signed-off-by: Gereon Dusella --- public/docs/yaml-metadata.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/docs/yaml-metadata.md b/public/docs/yaml-metadata.md index 48bc06ea43..e064da19b1 100644 --- a/public/docs/yaml-metadata.md +++ b/public/docs/yaml-metadata.md @@ -138,7 +138,7 @@ This option allows you to set options regarding the table of contents (toc). Cur > **maxDepth:** > default: not set (whioch will show everything until level 3 (h1 -- h3)) -> max: 5 (as defined by doctoc) +> max: 5 (as defined by md-toc.js) **Example** From 1248bc9cd4f973d4d19ed5855db79254b79a21bf Mon Sep 17 00:00:00 2001 From: Gereon Dusella Date: Wed, 3 Jun 2020 20:17:06 +0200 Subject: [PATCH 008/204] added default value `3` to CMD_DEFAULT_TOC_DEPTH Signed-off-by: Gereon Dusella --- lib/config/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/environment.js b/lib/config/environment.js index cbf0f4c13f..4a1621dd89 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -148,5 +148,5 @@ module.exports = { defaultUseHardbreak: toBooleanConfig(process.env.CMD_DEFAULT_USE_HARD_BREAK), linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE, autoVersionCheck: toBooleanConfig(process.env.CMD_AUTO_VERSION_CHECK), - defaultTocDepth: toIntegerConfig(process.env.CMD_DEFAULT_TOC_DEPTH) + defaultTocDepth: toIntegerConfig(process.env.CMD_DEFAULT_TOC_DEPTH, 3) } From c7013574e214a57ad2e54999a1cb638a84e40433 Mon Sep 17 00:00:00 2001 From: Gereon Dusella Date: Wed, 3 Jun 2020 20:40:23 +0200 Subject: [PATCH 009/204] added documentation to features.md Signed-off-by: Gereon Dusella --- public/docs/features.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/public/docs/features.md b/public/docs/features.md index c3f5fac931..8902bee7ca 100644 --- a/public/docs/features.md +++ b/public/docs/features.md @@ -82,7 +82,8 @@ View ## Table of Contents: You can look at the bottom right section of the view area, there is a _ToC_ button . Pressing that button will show you a current _Table of Contents_, and will highlight which section you're at. -ToCs support up to **three header levels**. +ToCs support up to **five header levels**, the **default** is **set to three**. The maxLevel can be set for each note by using +[YAML Metadata](./yaml-metadata) ## Permalink Every header will automatically add a permalink on the right side. @@ -133,12 +134,19 @@ You can provide advanced note information to set the browser behavior (visit abo - GA: set to use Google Analytics - disqus: set to use Disqus - slideOptions: setup slide mode options +- toc: set options of the Table of Contents. ## ToC: -Use the syntax `[TOC]` to embed table of content into your note. +Use the syntax `[TOC]` to embed table of content into your note. By default, three header levels are displayed. This can also be specified by using [YAML Metadata](./yaml-metadata). [TOC] +You can also specify the number of header levels by specifying the `maxLevel` like this: `[TOC maxLevel=1]` + +[TOC maxLevel=1] + + + ## Emoji You can type any emoji like this :smile: :smiley: :cry: :wink: > See full emoji list [here](http://www.emoji-cheat-sheet.com/). From 3438c5701b9ae355412fe509b35c62e5cb66f198 Mon Sep 17 00:00:00 2001 From: gereon Date: Mon, 13 Jul 2020 00:34:15 +0200 Subject: [PATCH 010/204] removed default value for toc depth seems to be set elsewhere Co-authored-by: Yukai Huang Signed-off-by: Gereon Dusella --- lib/config/environment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config/environment.js b/lib/config/environment.js index 4a1621dd89..cbf0f4c13f 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -148,5 +148,5 @@ module.exports = { defaultUseHardbreak: toBooleanConfig(process.env.CMD_DEFAULT_USE_HARD_BREAK), linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE, autoVersionCheck: toBooleanConfig(process.env.CMD_AUTO_VERSION_CHECK), - defaultTocDepth: toIntegerConfig(process.env.CMD_DEFAULT_TOC_DEPTH, 3) + defaultTocDepth: toIntegerConfig(process.env.CMD_DEFAULT_TOC_DEPTH) } From f42d1c3e3ef01a98d997f6bd9247724ddf9ff493 Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 20:54:08 +0900 Subject: [PATCH 011/204] Add privacyPolicyURL (CMD_PRIVACY_POLICY_URL) If you use Google OAuth, you need to add Privacy Policy to the top. https://support.google.com/cloud/answer/9110914#all-apps-zippy https://github.com/hackmdio/codimd/issues/1582#issuecomment-682270394 Signed-off-by: Tamotsu Takahashi --- app.js | 1 + lib/config/default.js | 1 + lib/config/environment.js | 1 + public/views/index/body.ejs | 1 + 4 files changed, 4 insertions(+) diff --git a/app.js b/app.js index 4980d45d02..700f3137c0 100644 --- a/app.js +++ b/app.js @@ -194,6 +194,7 @@ app.set('view engine', 'ejs') app.locals.useCDN = config.useCDN app.locals.serverURL = config.serverURL app.locals.sourceURL = config.sourceURL +app.locals.privacyPolicyURL = config.privacyPolicyURL app.locals.allowAnonymous = config.allowAnonymous app.locals.allowAnonymousEdits = config.allowAnonymousEdits app.locals.permission = config.permission diff --git a/lib/config/default.js b/lib/config/default.js index 95ee1940fe..0e7a818e19 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -37,6 +37,7 @@ module.exports = { defaultPermission: 'editable', dbURL: '', db: {}, + privacyPolicyURL: '', // ssl path sslKeyPath: '', sslCertPath: '', diff --git a/lib/config/environment.js b/lib/config/environment.js index 0867aecf54..7477a3c168 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -35,6 +35,7 @@ module.exports = { sessionSecret: process.env.CMD_SESSION_SECRET, sessionLife: toIntegerConfig(process.env.CMD_SESSION_LIFE), responseMaxLag: toIntegerConfig(process.env.CMD_RESPONSE_MAX_LAG), + privacyPolicyURL: process.env.CMD_PRIVACY_POLICY_URL, imageUploadType: process.env.CMD_IMAGE_UPLOAD_TYPE, imgur: { clientID: process.env.CMD_IMGUR_CLIENTID diff --git a/public/views/index/body.ejs b/public/views/index/body.ejs index db20b0e3c7..c5ee3cdde1 100644 --- a/public/views/index/body.ejs +++ b/public/views/index/body.ejs @@ -156,6 +156,7 @@ + <% if(privacyPolicyURL && privacyPolicyURL.length > 0) { %>

<%= __('Privacy Policy') %>

<% } %> From dc46c3d45edcc35dd857cd4fd67ec8a882a80823 Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 22:52:14 +0900 Subject: [PATCH 012/204] Follow Google's branding guideline https://github.com/hackmdio/codimd/issues/1582 Signed-off-by: Tamotsu Takahashi --- public/views/shared/signin-modal.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/views/shared/signin-modal.ejs b/public/views/shared/signin-modal.ejs index c209ef4372..3b22111f6e 100644 --- a/public/views/shared/signin-modal.ejs +++ b/public/views/shared/signin-modal.ejs @@ -44,8 +44,8 @@ <% } %> <% if (authProviders.google) { %> - + <%= __('Sign in via %s', 'Google') %> <% } %> <% if (authProviders.saml) { %> From 1920978c75345dc1ea3c758bbc9486f82ff52f7b Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 23:05:47 +0900 Subject: [PATCH 013/204] Adjust margin Signed-off-by: Tamotsu Takahashi --- public/views/shared/signin-modal.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/views/shared/signin-modal.ejs b/public/views/shared/signin-modal.ejs index 3b22111f6e..ae134cca93 100644 --- a/public/views/shared/signin-modal.ejs +++ b/public/views/shared/signin-modal.ejs @@ -44,8 +44,8 @@ <% } %> <% if (authProviders.google) { %> - - <%= __('Sign in via %s', 'Google') %> + + <%= __('Sign in via %s', 'Google') %> <% } %> <% if (authProviders.saml) { %> From 3df090302c8a9ba15fe30400e436a92934c9c1e2 Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Sat, 22 Aug 2020 18:05:23 +0900 Subject: [PATCH 014/204] Convert "include" directives to functions Signed-off-by: Tamotsu Takahashi --- public/views/codimd.ejs | 10 +++++----- public/views/codimd/body.ejs | 10 +++++----- public/views/codimd/foot.ejs | 4 ++-- public/views/codimd/head.ejs | 6 +++--- public/views/error.ejs | 6 +++--- public/views/index.ejs | 10 +++++----- public/views/index/body.ejs | 2 +- public/views/index/foot.ejs | 4 ++-- public/views/index/head.ejs | 6 +++--- public/views/pretty.ejs | 14 +++++++------- public/views/slide.ejs | 14 +++++++------- 11 files changed, 43 insertions(+), 43 deletions(-) diff --git a/public/views/codimd.ejs b/public/views/codimd.ejs index 7818346c39..1cdadba288 100644 --- a/public/views/codimd.ejs +++ b/public/views/codimd.ejs @@ -2,14 +2,14 @@ - <%- include codimd/head %> + <%- include('codimd/head'); %> - <%- include codimd/header %> - <%- include codimd/body %> - <%- include codimd/footer %> - <%- include codimd/foot %> + <%- include('codimd/header'); %> + <%- include('codimd/body'); %> + <%- include('codimd/footer'); %> + <%- include('codimd/foot'); %> diff --git a/public/views/codimd/body.ejs b/public/views/codimd/body.ejs index c688ae38b8..1031532872 100644 --- a/public/views/codimd/body.ejs +++ b/public/views/codimd/body.ejs @@ -246,8 +246,8 @@ -<%- include ../shared/refresh-modal %> -<%- include ../shared/signin-modal %> -<%- include ../shared/help-modal %> -<%- include ../shared/revision-modal %> -<%- include ../shared/pandoc-export-modal %> +<%- include('../shared/refresh-modal'); %> +<%- include('../shared/signin-modal'); %> +<%- include('../shared/help-modal'); %> +<%- include('../shared/revision-modal'); %> +<%- include('../shared/pandoc-export-modal'); %> diff --git a/public/views/codimd/foot.ejs b/public/views/codimd/foot.ejs index 243fa40ad6..e3e74670c6 100644 --- a/public/views/codimd/foot.ejs +++ b/public/views/codimd/foot.ejs @@ -25,10 +25,10 @@ -<%- include ../build/index-scripts %> +<%- include('../build/index-scripts'); %> <% } else { %> -<%- include ../build/index-pack-scripts %> +<%- include('../build/index-pack-scripts'); %> <% } %> diff --git a/public/views/codimd/head.ejs b/public/views/codimd/head.ejs index 810781bbad..c0cd926402 100644 --- a/public/views/codimd/head.ejs +++ b/public/views/codimd/head.ejs @@ -14,12 +14,12 @@ -<%- include ../build/index-header %> -<%- include ../shared/polyfill %> +<%- include('../build/index-header'); %> +<%- include('../shared/polyfill'); %> <% } else { %> -<%- include ../build/index-pack-header %> +<%- include('../build/index-pack-header'); %> <% } %> diff --git a/public/views/error.ejs b/public/views/error.ejs index 3ed76c8ce5..9e78ed7ee1 100644 --- a/public/views/error.ejs +++ b/public/views/error.ejs @@ -2,18 +2,18 @@ - <%- include codimd/head %> + <%- include('codimd/head'); %> - <%- include codimd/header %> + <%- include('codimd/header'); %>

<%- code %> <%- detail %> <%- msg %>

- <%- include codimd/footer %> + <%- include('codimd/footer'); %> diff --git a/public/views/index.ejs b/public/views/index.ejs index 5732db4a3c..1ec4eb81a6 100644 --- a/public/views/index.ejs +++ b/public/views/index.ejs @@ -2,14 +2,14 @@ - <%- include index/head %> + <%- include('index/head'); %> - <%- include index/header %> - <%- include index/body %> - <%- include index/footer %> - <%- include index/foot %> + <%- include('index/header'); %> + <%- include('index/body'); %> + <%- include('index/footer'); %> + <%- include('index/foot'); %> diff --git a/public/views/index/body.ejs b/public/views/index/body.ejs index db20b0e3c7..ee4f3e0291 100644 --- a/public/views/index/body.ejs +++ b/public/views/index/body.ejs @@ -201,4 +201,4 @@ -<%- include ../shared/signin-modal %> +<%- include('../shared/signin-modal'); %> diff --git a/public/views/index/foot.ejs b/public/views/index/foot.ejs index e9af48e552..1d261e9a58 100644 --- a/public/views/index/foot.ejs +++ b/public/views/index/foot.ejs @@ -7,7 +7,7 @@ -<%- include ../build/cover-scripts %> +<%- include('../build/cover-scripts'); %> <% } else { %> -<%- include ../build/cover-pack-scripts %> +<%- include('../build/cover-pack-scripts'); %> <% } %> diff --git a/public/views/index/head.ejs b/public/views/index/head.ejs index 8a1f08cf9c..58bf3c6dd3 100644 --- a/public/views/index/head.ejs +++ b/public/views/index/head.ejs @@ -15,10 +15,10 @@ -<%- include ../build/cover-header %> -<%- include ../shared/polyfill %> +<%- include('../build/cover-header'); %> +<%- include('../shared/polyfill'); %> <% } else { %> -<%- include ../build/cover-pack-header %> +<%- include('../build/cover-pack-header'); %> <% } %> diff --git a/public/views/pretty.ejs b/public/views/pretty.ejs index 30248a7010..5f03a76713 100644 --- a/public/views/pretty.ejs +++ b/public/views/pretty.ejs @@ -26,13 +26,13 @@ - <%- include build/pretty-header %> - <%- include shared/polyfill %> + <%- include('build/pretty-header'); %> + <%- include('shared/polyfill'); %> <% } else { %> - <%- include build/pretty-pack-header %> + <%- include('build/pretty-pack-header'); %> <% } %> @@ -71,7 +71,7 @@ <% if(typeof disqus !== 'undefined' && disqus) { %>
- <%- include shared/disqus %> + <%- include('shared/disqus'); %>
<% } %> @@ -100,11 +100,11 @@ -<%- include build/pretty-scripts %> +<%- include('build/pretty-scripts'); %> <% } else { %> -<%- include build/pretty-pack-scripts %> +<%- include('build/pretty-pack-scripts'); %> <% } %> -<%- include shared/ga %> +<%- include('shared/ga'); %> diff --git a/public/views/slide.ejs b/public/views/slide.ejs index 83d1539a31..e7c0ef6d1f 100644 --- a/public/views/slide.ejs +++ b/public/views/slide.ejs @@ -21,14 +21,14 @@ - <%- include build/slide-header %> - <%- include shared/polyfill %> + <%- include('build/slide-header'); %> + <%- include('shared/polyfill'); %> <% } else { %> - <%- include build/slide-pack-header %> + <%- include('build/slide-pack-header'); %> <% } %> @@ -83,7 +83,7 @@ <% if(typeof disqus !== 'undefined' && disqus) { %>
- <%- include shared/disqus %> + <%- include('shared/disqus'); %>
<% } %> @@ -112,14 +112,14 @@ - <%- include build/slide-scripts %> + <%- include('build/slide-scripts'); %> <% } else { %> - <%- include build/slide-pack-scripts %> + <%- include('build/slide-pack-scripts'); %> <% } %> -<%- include shared/ga %> +<%- include('shared/ga'); %> From 0aff524bbae0cd397e9bb3caf8fb15d1e5d4ca5e Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 17:19:38 +0900 Subject: [PATCH 015/204] Make permission labels translatable. https://github.com/hackmdio/codimd/issues/1581#issuecomment-683236111 Signed-off-by: Tamotsu Takahashi --- public/views/codimd/body.ejs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/public/views/codimd/body.ejs b/public/views/codimd/body.ejs index c688ae38b8..a48b4a400a 100644 --- a/public/views/codimd/body.ejs +++ b/public/views/codimd/body.ejs @@ -15,20 +15,20 @@
From 66fdf7b49c8d88c3d785749864651bdab5e78046 Mon Sep 17 00:00:00 2001 From: Tamotsu Takahashi Date: Tue, 1 Sep 2020 19:17:11 +0900 Subject: [PATCH 016/204] Make permission and status translatable Move HTML from JS to EJS. https://github.com/hackmdio/codimd/issues/1581#issuecomment-683236111 https://github.com/hackmdio/codimd/issues/1581#issuecomment-683431173 Signed-off-by: Tamotsu Takahashi --- public/js/index.js | 77 +++++++---------------------- public/js/lib/editor/ui-elements.js | 5 ++ public/views/codimd/body.ejs | 22 +++++---- public/views/codimd/header.ejs | 9 +++- 4 files changed, 44 insertions(+), 69 deletions(-) diff --git a/public/js/index.js b/public/js/index.js index c736cb7f2c..f5dab51b9c 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -237,21 +237,9 @@ const supportExtraTags = [ } ] const statusType = { - connected: { - msg: 'CONNECTED', - label: 'label-warning', - fa: 'fa-wifi' - }, - online: { - msg: 'ONLINE', - label: 'label-primary', - fa: 'fa-users' - }, - offline: { - msg: 'OFFLINE', - label: 'label-danger', - fa: 'fa-plug' - } + connected: 1, + online: 2, + offline: 3 } // global vars @@ -723,43 +711,23 @@ function checkTocStyle () { function showStatus (type, num) { currentStatus = type - var shortStatus = ui.toolbar.shortStatus - var status = ui.toolbar.status - var label = $('') - var fa = $('') - var msg = '' - var shortMsg = '' - shortStatus.html('') - status.html('') + ui.toolbar.statusConnected.hide() + ui.toolbar.statusOnline.hide() + ui.toolbar.statusOffline.hide() switch (currentStatus) { case statusType.connected: - label.addClass(statusType.connected.label) - fa.addClass(statusType.connected.fa) - msg = statusType.connected.msg + ui.toolbar.statusConnected.show() break case statusType.online: - label.addClass(statusType.online.label) - fa.addClass(statusType.online.fa) - shortMsg = num - msg = num + ' ' + statusType.online.msg + ui.toolbar.statusShortMsg.text(num) + ui.toolbar.statusOnline.show() break case statusType.offline: - label.addClass(statusType.offline.label) - fa.addClass(statusType.offline.fa) - msg = statusType.offline.msg + ui.toolbar.statusOffline.show() break } - - label.append(fa) - var shortLabel = label.clone() - - shortLabel.append(' ' + shortMsg) - shortStatus.append(shortLabel) - - label.append(' ' + msg) - status.append(label) } function toggleMode () { @@ -1647,41 +1615,34 @@ function updatePermission (newPermission) { permission = newPermission if (window.loaded) refreshView() } - var label = null - var title = null + ui.infobar.permission.label.hide() switch (permission) { case 'freely': - label = ' Freely' - title = 'Anyone can edit' + $('#permissionLabelFreely').show() break case 'editable': - label = ' Editable' - title = 'Signed people can edit' + $('#permissionLabelEditable').show() break case 'limited': - label = ' Limited' - title = 'Signed people can edit (forbid guest)' + $('#permissionLabelLimited').show() break case 'locked': - label = ' Locked' - title = 'Only owner can edit' + $('#permissionLabelLocked').show() break case 'protected': - label = ' Protected' - title = 'Only owner can edit (forbid guest)' + $('#permissionLabelProtected').show() break case 'private': - label = ' Private' - title = 'Only owner can view & edit' + $('#permissionLabelPrivate').show() break } if (personalInfo.userid && window.owner && personalInfo.userid === window.owner) { - label += ' ' + ui.infobar.permission.labelCaretDown.show() ui.infobar.permission.label.removeClass('disabled') } else { + ui.infobar.permission.labelCaretDown.hide() ui.infobar.permission.label.addClass('disabled') } - ui.infobar.permission.label.html(label).attr('title', title) } function havePermission () { diff --git a/public/js/lib/editor/ui-elements.js b/public/js/lib/editor/ui-elements.js index d084607fb1..bedf51fcba 100644 --- a/public/js/lib/editor/ui-elements.js +++ b/public/js/lib/editor/ui-elements.js @@ -9,6 +9,10 @@ export const getUIElements = () => ({ toolbar: { shortStatus: $('.ui-short-status'), status: $('.ui-status'), + statusShortMsg: $('.ui-status-short-msg'), + statusConnected: $('.ui-status-connected'), + statusOnline: $('.ui-status-online'), + statusOffline: $('.ui-status-offline'), new: $('.ui-new'), publish: $('.ui-publish'), extra: { @@ -46,6 +50,7 @@ export const getUIElements = () => ({ permission: { permission: $('.ui-permission'), label: $('.ui-permission-label'), + labelCaretDown: $('.ui-permission-caret-down'), freely: $('.ui-permission-freely'), editable: $('.ui-permission-editable'), locked: $('.ui-permission-locked'), diff --git a/public/views/codimd/body.ejs b/public/views/codimd/body.ejs index a48b4a400a..0a2f17eea9 100644 --- a/public/views/codimd/body.ejs +++ b/public/views/codimd/body.ejs @@ -12,15 +12,19 @@ - -