Skip to content

Commit 75ee5ad

Browse files
committed
Merge branch 'develop' into feature/configurable-break-style
2 parents 82b5e98 + f871eff commit 75ee5ad

File tree

16 files changed

+172
-58
lines changed

16 files changed

+172
-58
lines changed

config.json.example

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"db": {
44
"dialect": "sqlite",
55
"storage": ":memory:"
6-
}
6+
},
7+
"linkifyHeaderStyle": "gfm"
78
},
89
"development": {
910
"loglevel": "debug",
@@ -13,7 +14,8 @@
1314
"db": {
1415
"dialect": "sqlite",
1516
"storage": "./db.codimd.sqlite"
16-
}
17+
},
18+
"linkifyHeaderStyle": "gfm"
1719
},
1820
"production": {
1921
"domain": "localhost",
@@ -127,6 +129,7 @@
127129
"plantuml":
128130
{
129131
"server": "https://www.plantuml.com/plantuml"
130-
}
132+
},
133+
"linkifyHeaderStyle": "gfm"
131134
}
132135
}

deployments/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ RUN set -xe && \
1818
FROM hackmdio/runtime:1.0.4
1919
USER hackmd
2020
WORKDIR /home/hackmd/app
21-
COPY --from=BUILD /home/hackmd/app .
21+
COPY --chown=1500:1500 --from=BUILD /home/hackmd/app .
2222
EXPOSE 3000
2323
ENTRYPOINT ["/home/hackmd/app/docker-entrypoint.sh"]

lib/config/default.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ module.exports = {
104104
consumerSecret: undefined
105105
},
106106
github: {
107+
enterpriseURL: undefined, // if you use github.com, not need to specify
107108
clientID: undefined,
108109
clientSecret: undefined
109110
},
@@ -163,5 +164,19 @@ module.exports = {
163164
allowGravatar: true,
164165
allowPDFExport: true,
165166
openID: false,
166-
defaultUseHardbreak: true
167+
defaultUseHardbreak: true,
168+
// linkifyHeaderStyle - How is a header text converted into a link id.
169+
// Header Example: "3.1. Good Morning my Friend! - Do you have 5$?"
170+
// * 'keep-case' is the legacy CodiMD value.
171+
// Generated id: "31-Good-Morning-my-Friend---Do-you-have-5"
172+
// * 'lower-case' is the same like legacy (see above), but converted to lower-case.
173+
// Generated id: "#31-good-morning-my-friend---do-you-have-5"
174+
// * 'gfm' _GitHub-Flavored Markdown_ style as described here:
175+
// https://gist.github.com/asabaylus/3071099#gistcomment-1593627
176+
// It works like 'lower-case', but making sure the ID is unique.
177+
// This is What GitHub, GitLab and (hopefully) most other tools use.
178+
// Generated id: "31-good-morning-my-friend---do-you-have-5"
179+
// 2nd appearance: "31-good-morning-my-friend---do-you-have-5-1"
180+
// 3rd appearance: "31-good-morning-my-friend---do-you-have-5-2"
181+
linkifyHeaderStyle: 'keep-case'
167182
}

lib/config/environment.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ module.exports = {
6666
consumerSecret: process.env.CMD_TWITTER_CONSUMERSECRET
6767
},
6868
github: {
69+
enterpriseURL: process.env.CMD_GITHUB_ENTERPRISE_URL,
6970
clientID: process.env.CMD_GITHUB_CLIENTID,
7071
clientSecret: process.env.CMD_GITHUB_CLIENTSECRET
7172
},
@@ -136,5 +137,6 @@ module.exports = {
136137
allowGravatar: toBooleanConfig(process.env.CMD_ALLOW_GRAVATAR),
137138
allowPDFExport: toBooleanConfig(process.env.CMD_ALLOW_PDF_EXPORT),
138139
openID: toBooleanConfig(process.env.CMD_OPENID),
139-
defaultUseHardbreak: toBooleanConfig(process.env.CMD_DEFAULT_USE_HARD_BREAK)
140+
defaultUseHardbreak: toBooleanConfig(process.env.CMD_DEFAULT_USE_HARD_BREAK),
141+
linkifyHeaderStyle: process.env.CMD_LINKIFY_HEADER_STYLE
140142
}

lib/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ config.sslCAPath.forEach(function (capath, i, array) {
200200
array[i] = path.resolve(appRootPath, capath)
201201
})
202202

203+
config.appRootPath = appRootPath
203204
config.sslCertPath = path.resolve(appRootPath, config.sslCertPath)
204205
config.sslKeyPath = path.resolve(appRootPath, config.sslKeyPath)
205206
config.dhParamPath = path.resolve(appRootPath, config.dhParamPath)

lib/models/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ module.exports = function (sequelize, DataTypes) {
103103
else photo += '?size=bigger'
104104
break
105105
case 'github':
106-
photo = 'https://avatars.githubusercontent.com/u/' + profile.id
106+
if (profile.photos && profile.photos[0]) photo = profile.photos[0].value.replace('?', '')
107+
else photo = 'https://avatars.githubusercontent.com/u/' + profile.id
107108
if (bigger) photo += '?s=400'
108109
else photo += '?s=96'
109110
break

lib/response.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,22 @@ function actionPDF (req, res, note) {
316316
var content = extracted.markdown
317317
var title = models.Note.decodeTitle(note.title)
318318

319+
var highlightCssPath = path.join(config.appRootPath, '/node_modules/highlight.js/styles/github-gist.css')
320+
319321
if (!fs.existsSync(config.tmpPath)) {
320322
fs.mkdirSync(config.tmpPath)
321323
}
322-
var path = config.tmpPath + '/' + Date.now() + '.pdf'
324+
var pdfPath = config.tmpPath + '/' + Date.now() + '.pdf'
323325
content = content.replace(/\]\(\//g, '](' + url + '/')
324-
markdownpdf().from.string(content).to(path, function () {
325-
if (!fs.existsSync(path)) {
326-
logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + path)
326+
var markdownpdfOptions = {
327+
highlightCssPath: highlightCssPath
328+
}
329+
markdownpdf(markdownpdfOptions).from.string(content).to(pdfPath, function () {
330+
if (!fs.existsSync(pdfPath)) {
331+
logger.error('PDF seems to not be generated as expected. File doesn\'t exist: ' + pdfPath)
327332
return errorInternalError(res)
328333
}
329-
var stream = fs.createReadStream(path)
334+
var stream = fs.createReadStream(pdfPath)
330335
var filename = title
331336
// Be careful of special characters
332337
filename = encodeURIComponent(filename)
@@ -336,7 +341,7 @@ function actionPDF (req, res, note) {
336341
res.setHeader('Content-Type', 'application/pdf; charset=UTF-8')
337342
res.setHeader('X-Robots-Tag', 'noindex, nofollow') // prevent crawling
338343
stream.pipe(res)
339-
fs.unlinkSync(path)
344+
fs.unlinkSync(pdfPath)
340345
})
341346
}
342347

lib/web/auth/github/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ const GithubStrategy = require('passport-github').Strategy
66
const config = require('../../../config')
77
const response = require('../../../response')
88
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
9+
const { URL } = require('url')
910

1011
const githubAuth = module.exports = Router()
1112

13+
function githubUrl (path) {
14+
return config.github.enterpriseURL && new URL(path, config.github.enterpriseURL).toString()
15+
}
16+
1217
passport.use(new GithubStrategy({
1318
clientID: config.github.clientID,
1419
clientSecret: config.github.clientSecret,
15-
callbackURL: config.serverURL + '/auth/github/callback'
20+
callbackURL: config.serverURL + '/auth/github/callback',
21+
authorizationURL: githubUrl('login/oauth/authorize'),
22+
tokenURL: githubUrl('login/oauth/access_token'),
23+
userProfileURL: githubUrl('api/v3/user')
1624
}, passportGeneralCallback))
1725

1826
githubAuth.get('/auth/github', function (req, res, next) {

lib/web/auth/gitlab/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ const GitlabStrategy = require('passport-gitlab2').Strategy
66
const config = require('../../../config')
77
const response = require('../../../response')
88
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
9+
const HttpsProxyAgent = require('https-proxy-agent')
910

1011
const gitlabAuth = module.exports = Router()
1112

12-
passport.use(new GitlabStrategy({
13+
const gitlabAuthStrategy = new GitlabStrategy({
1314
baseURL: config.gitlab.baseURL,
1415
clientID: config.gitlab.clientID,
1516
clientSecret: config.gitlab.clientSecret,
1617
scope: config.gitlab.scope,
1718
callbackURL: config.serverURL + '/auth/gitlab/callback'
18-
}, passportGeneralCallback))
19+
}, passportGeneralCallback)
20+
21+
if (process.env['https_proxy']) {
22+
const httpsProxyAgent = new HttpsProxyAgent(process.env['https_proxy'])
23+
gitlabAuthStrategy._oauth2.setAgent(httpsProxyAgent)
24+
}
25+
26+
passport.use(gitlabAuthStrategy)
1927

2028
gitlabAuth.get('/auth/gitlab', function (req, res, next) {
2129
setReturnToFromReferer(req)

lib/web/statusRouter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ statusRouter.get('/config', function (req, res) {
100100
plantumlServer: config.plantuml.server,
101101
DROPBOX_APP_KEY: config.dropbox.appKey,
102102
allowedUploadMimeTypes: config.allowedUploadMimeTypes,
103-
defaultUseHardbreak: config.defaultUseHardbreak
103+
defaultUseHardbreak: config.defaultUseHardbreak,
104+
linkifyHeaderStyle: config.linkifyHeaderStyle
104105
}
105106
res.set({
106107
'Cache-Control': 'private', // only cache by client

0 commit comments

Comments
 (0)