Skip to content

Commit ca9c4b3

Browse files
authored
Merge pull request #991 from SISheogorath/feature/fullversion
Add full version string (and no AGPL violation detection)
2 parents 4e5e7df + bcc914a commit ca9c4b3

File tree

9 files changed

+52
-7
lines changed

9 files changed

+52
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ There are some config settings you need to change in the files below.
260260
| `CMD_HSTS_PRELOAD` | `true` | whether to allow preloading of the site's HSTS status (e.g. into browsers) |
261261
| `CMD_CSP_ENABLE` | `true` | whether to enable Content Security Policy (directives cannot be configured with environment variables) |
262262
| `CMD_CSP_REPORTURI` | `https://<someid>.report-uri.com/r/d/csp/enforce` | Allows to add a URL for CSP reports in case of violations |
263+
| `CMD_SOURCE_URL` | `https://github.com/hackmdio/codimd/tree/<current commit>` | Provides the link to the source code of CodiMD on the entry page (Please, make sure you change this when you run a modified version) |
263264

264265
***Note:** Due to the rename process we renamed all `HMD_`-prefix variables to be `CMD_`-prefixed. The old ones continue to work.*
265266

@@ -310,6 +311,7 @@ There are some config settings you need to change in the files below.
310311
| `minio` | `{ "accessKey": "YOUR_MINIO_ACCESS_KEY", "secretKey": "YOUR_MINIO_SECRET_KEY", "endpoint": "YOUR_MINIO_HOST", port: 9000, secure: true }` | When `imageUploadType` is set to `minio`, you need to set this key. Also checkout our [Minio Image Upload Guide](docs/guides/minio-image-upload.md) |
311312
| `s3` | `{ "accessKeyId": "YOUR_S3_ACCESS_KEY_ID", "secretAccessKey": "YOUR_S3_ACCESS_KEY", "region": "YOUR_S3_REGION" }` | When `imageuploadtype` be set to `s3`, you would also need to setup this key, check our [S3 Image Upload Guide](docs/guides/s3-image-upload.md) |
312313
| `s3bucket` | `YOUR_S3_BUCKET_NAME` | bucket name when `imageUploadType` is set to `s3` or `minio` |
314+
| `sourceURL` | `https://github.com/hackmdio/codimd/tree/<current commit>` | Provides the link to the source code of CodiMD on the entry page (Please, make sure you change this when you run a modified version) |
313315

314316
<sup>1</sup>: relative paths are based on CodiMD's base directory
315317

app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ app.set('view engine', 'ejs')
178178
// set generally available variables for all views
179179
app.locals.useCDN = config.useCDN
180180
app.locals.serverURL = config.serverURL
181+
app.locals.sourceURL = config.sourceURL
181182
app.locals.allowAnonymous = config.allowAnonymous
182183
app.locals.allowAnonymousEdits = config.allowAnonymousEdits
183184
app.locals.allowPDFExport = config.allowPDFExport

lib/config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {toBooleanConfig, toArrayConfig, toIntegerConfig} = require('./utils')
44

55
module.exports = {
6+
sourceURL: process.env.CMD_SOURCE_URL,
67
domain: process.env.CMD_DOMAIN,
78
urlPath: process.env.CMD_URL_PATH,
89
host: process.env.CMD_HOST,

lib/config/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {merge} = require('lodash')
88
const deepFreeze = require('deep-freeze')
99
const {Environment, Permission} = require('./enum')
1010
const logger = require('../logger')
11+
const {getGitCommit, getGitHubURL} = require('./utils')
1112

1213
const appRootPath = path.resolve(__dirname, '../../')
1314
const env = process.env.NODE_ENV || Environment.development
@@ -16,11 +17,17 @@ const debugConfig = {
1617
}
1718

1819
// Get version string from package.json
19-
const {version} = require(path.join(appRootPath, 'package.json'))
20+
const {version, repository} = require(path.join(appRootPath, 'package.json'))
21+
22+
const commitID = getGitCommit(appRootPath)
23+
const sourceURL = getGitHubURL(repository.url, commitID || version)
24+
const fullversion = commitID ? `${version}-${commitID}` : version
2025

2126
const packageConfig = {
2227
version: version,
23-
minimumCompatibleVersion: '0.5.0'
28+
minimumCompatibleVersion: '0.5.0',
29+
fullversion: fullversion,
30+
sourceURL: sourceURL
2431
}
2532

2633
const configFilePath = path.resolve(appRootPath, process.env.CMD_CONFIG_FILE ||

lib/config/utils.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict'
22

3+
const fs = require('fs')
4+
const path = require('path')
5+
36
exports.toBooleanConfig = function toBooleanConfig (configValue) {
47
if (configValue && typeof configValue === 'string') {
58
return (configValue === 'true')
@@ -20,3 +23,33 @@ exports.toIntegerConfig = function toIntegerConfig (configValue) {
2023
}
2124
return configValue
2225
}
26+
27+
exports.getGitCommit = function getGitCommit (repodir) {
28+
if (!fs.existsSync(repodir + '/.git/HEAD')) {
29+
return undefined
30+
}
31+
let reference = fs.readFileSync(repodir + '/.git/HEAD', 'utf8')
32+
if (reference.startsWith('ref: ')) {
33+
reference = reference.substr(5).replace('\n', '')
34+
reference = fs.readFileSync(path.resolve(repodir + '/.git', reference), 'utf8')
35+
}
36+
reference = reference.substr(5).replace('\n', '')
37+
return reference
38+
}
39+
40+
exports.getGitHubURL = function getGitHubURL (repo, reference) {
41+
// if it's not a github reference, we handle handle that anyway
42+
if (!repo.startsWith('https://github.com') && !repo.startsWith('[email protected]')) {
43+
return repo
44+
}
45+
if (repo.startsWith('[email protected]') || repo.startsWith('ssh://[email protected]')) {
46+
repo = repo.replace(/^(ssh:\/\/)?git@github.com:/, 'https://github.com/')
47+
}
48+
49+
if (repo.endsWith('.git')) {
50+
repo = repo.replace(/\.git$/, '/')
51+
} else if (!repo.endsWith('/')) {
52+
repo = repo + '/'
53+
}
54+
return repo + 'tree/' + reference
55+
}

lib/realtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ function connection (socket) {
887887
// check version
888888
socket.on('version', function () {
889889
socket.emit('version', {
890-
version: config.version,
890+
version: config.fullversion,
891891
minimumCompatibleVersion: config.minimumCompatibleVersion
892892
})
893893
})

lib/web/statusRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ statusRouter.get('/config', function (req, res) {
9696
domain: config.domain,
9797
urlpath: config.urlPath,
9898
debug: config.debug,
99-
version: config.version,
99+
version: config.fullversion,
100100
DROPBOX_APP_KEY: config.dropbox.appKey,
101101
allowedUploadMimeTypes: config.allowedUploadMimeTypes
102102
}

locales/en.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,6 @@
112112
"This will delete your account, all notes that are owned by you and remove all references to your account from other notes.": "This will delete your account, all notes that are owned by you and remove all references to your account from other notes.",
113113
"Delete user": "Delete user",
114114
"Export user data": "Export user data",
115-
"Help us translating on %s": "Help us translating on %s"
116-
}
115+
"Help us translating on %s": "Help us translating on %s",
116+
"Source Code": "Source Code"
117+
}

public/views/index/body.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<option value="id">Bahasa Indonesia</option>
151151
</select>
152152
<p>
153-
Powered by <a href="https://codimd.org">CodiMD</a> | <a href="<%- serverURL %>/s/release-notes" target="_blank" rel="noopener"><%= __('Releases') %></a><% if(privacyStatement) { %> | <a href="<%- serverURL %>/s/privacy" target="_blank" rel="noopener"><%= __('Privacy') %></a><% } %><% if(termsOfUse) { %> | <a href="<%- serverURL %>/s/terms-of-use" target="_blank" rel="noopener"><%= __('Terms of Use') %></a><% } %>
153+
Powered by <a href="https://codimd.org">CodiMD</a> | <a href="<%- serverURL %>/s/release-notes" target="_blank" rel="noopener"><%= __('Releases') %></a>| <a href="<%- sourceURL %>" target="_blank" rel="noopener"><%= __('Source Code') %></a><% if(privacyStatement) { %> | <a href="<%- serverURL %>/s/privacy" target="_blank" rel="noopener"><%= __('Privacy') %></a><% } %><% if(termsOfUse) { %> | <a href="<%- serverURL %>/s/terms-of-use" target="_blank" rel="noopener"><%= __('Terms of Use') %></a><% } %>
154154
</p>
155155
<h6 class="social-foot">
156156
<%- __('Follow us on %s and %s.', '<a href="https://github.com/hackmdio/CodiMD" target="_blank" rel="noopener"><i class="fa fa-github"></i> GitHub</a>, <a href="https://riot.im/app/#/room/#codimd:matrix.org" target="_blank" rel="noopener"><i class="fa fa-comments"></i> Riot</a>', '<a href="https://translate.codimd.org" target="_blank" rel="noopener"><i class="fa fa-globe"></i> POEditor</a>') %>

0 commit comments

Comments
 (0)