summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app.js18
-rw-r--r--lib/config/default.js1
-rw-r--r--lib/config/index.js1
-rw-r--r--lib/response.js9
-rw-r--r--lib/web/imageRouter/filesystem.js2
-rw-r--r--lib/web/statusRouter.js17
l---------locales/zh.json1
-rw-r--r--public/views/includes/scripts.ejs2
8 files changed, 29 insertions, 22 deletions
diff --git a/app.js b/app.js
index 772073b0..bfb5a49a 100644
--- a/app.js
+++ b/app.js
@@ -26,22 +26,6 @@ var response = require('./lib/response')
var models = require('./lib/models')
var csp = require('./lib/csp')
-// generate front-end constants by template
-var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs')
-var data = {
- domain: config.domain,
- urlpath: config.urlPath,
- debug: config.debug,
- version: config.version,
- DROPBOX_APP_KEY: config.dropbox.appKey,
- allowedUploadMimeTypes: config.allowedUploadMimeTypes
-}
-
-ejs.renderFile(constpath, data, {}, function (err, str) {
- if (err) throw new Error(err)
- fs.writeFileSync(path.join(__dirname, './public/build/constant.js'), str)
-})
-
// server setup
var app = express()
var server = null
@@ -129,7 +113,7 @@ if (config.csp.enable) {
}
i18n.configure({
- locales: ['en', 'zh', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', 'uk', 'hi', 'sv', 'eo', 'da', 'ko'],
+ locales: ['en', 'zh-CN', 'zh-TW', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', 'uk', 'hi', 'sv', 'eo', 'da', 'ko'],
cookie: 'locale',
directory: path.join(__dirname, '/locales'),
updateFiles: config.updateI18nFiles
diff --git a/lib/config/default.js b/lib/config/default.js
index ec44ae78..8e71029e 100644
--- a/lib/config/default.js
+++ b/lib/config/default.js
@@ -45,6 +45,7 @@ module.exports = {
errorPath: './public/views/error.ejs',
prettyPath: './public/views/pretty.ejs',
slidePath: './public/views/slide.ejs',
+ constantsPath: './public/js/lib/common/constant.ejs',
uploadsPath: './public/uploads',
// session
sessionName: 'connect.sid',
diff --git a/lib/config/index.js b/lib/config/index.js
index b8bf64cc..79330443 100644
--- a/lib/config/index.js
+++ b/lib/config/index.js
@@ -173,6 +173,7 @@ config.hackmdPath = path.join(appRootPath, config.hackmdPath)
config.errorPath = path.join(appRootPath, config.errorPath)
config.prettyPath = path.join(appRootPath, config.prettyPath)
config.slidePath = path.join(appRootPath, config.slidePath)
+config.constantsPath = path.join(appRootPath, config.constantsPath)
config.uploadsPath = path.join(appRootPath, config.uploadsPath)
// make config readonly
diff --git a/lib/response.js b/lib/response.js
index 4cfa9a74..d1e5e15c 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -145,6 +145,8 @@ function responseHackMD (res, note) {
function newNote (req, res, next) {
var owner = null
+ var body = req.body ? req.body : ''
+ body = body.replace(/[\r]/g, '')
if (req.isAuthenticated()) {
owner = req.user.id
} else if (!config.allowAnonymous) {
@@ -153,7 +155,7 @@ function newNote (req, res, next) {
models.Note.create({
ownerId: owner,
alias: req.alias ? req.alias : null,
- content: req.body ? req.body : ''
+ content: body
}).then(function (note) {
return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id))
}).catch(function (err) {
@@ -327,15 +329,18 @@ function actionInfo (req, res, note) {
}
function actionPDF (req, res, note) {
+ var url = config.serverURL || 'http://' + req.get('host')
var body = note.content
var extracted = models.Note.extractMeta(body)
+ var content = extracted.markdown
var title = models.Note.decodeTitle(note.title)
if (!fs.existsSync(config.tmpPath)) {
fs.mkdirSync(config.tmpPath)
}
var path = config.tmpPath + '/' + Date.now() + '.pdf'
- markdownpdf().from.string(extracted.markdown).to(path, function () {
+ content = content.replace(/\]\(\//g, '](' + url + '/')
+ markdownpdf().from.string(content).to(path, function () {
var stream = fs.createReadStream(path)
var filename = title
// Be careful of special characters
diff --git a/lib/web/imageRouter/filesystem.js b/lib/web/imageRouter/filesystem.js
index 145876a9..4bf82b31 100644
--- a/lib/web/imageRouter/filesystem.js
+++ b/lib/web/imageRouter/filesystem.js
@@ -15,5 +15,5 @@ exports.uploadImage = function (imagePath, callback) {
return
}
- callback(null, url.resolve(config.serverURL + '/', imagePath.match(/^public\/(.+$)/)[1]))
+ callback(null, url.resolve(config.serverURL + '/', imagePath.match(/public\/(.+)$/)[1]))
}
diff --git a/lib/web/statusRouter.js b/lib/web/statusRouter.js
index d22fac47..4495a28e 100644
--- a/lib/web/statusRouter.js
+++ b/lib/web/statusRouter.js
@@ -90,3 +90,20 @@ statusRouter.post('/temp', urlencodedParser, function (req, res) {
}
}
})
+
+statusRouter.get('/config', function (req, res) {
+ var data = {
+ domain: config.domain,
+ urlpath: config.urlPath,
+ debug: config.debug,
+ version: config.version,
+ DROPBOX_APP_KEY: config.dropbox.appKey,
+ allowedUploadMimeTypes: config.allowedUploadMimeTypes
+ }
+ res.set({
+ 'Cache-Control': 'private', // only cache by client
+ 'X-Robots-Tag': 'noindex, nofollow', // prevent crawling
+ 'HackMD-Version': config.version
+ })
+ res.render(config.constantsPath, data)
+})
diff --git a/locales/zh.json b/locales/zh.json
deleted file mode 120000
index 77c7eac5..00000000
--- a/locales/zh.json
+++ /dev/null
@@ -1 +0,0 @@
-locales/zh-TW.json \ No newline at end of file
diff --git a/public/views/includes/scripts.ejs b/public/views/includes/scripts.ejs
index 8766894a..df8fbc00 100644
--- a/public/views/includes/scripts.ejs
+++ b/public/views/includes/scripts.ejs
@@ -1,4 +1,4 @@
-<script src="<%= webpackConfig.output.baseUrl %>/build/constant.js"></script>
+<script src="<%= webpackConfig.output.baseUrl %>/config"></script>
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
<script src="<%= webpackConfig.output.baseUrl %><%= htmlWebpackPlugin.files.chunks[chunk].entry %>" defer></script>
<% } %>