Skip to content

Commit 19a677f

Browse files
committed
derive a new edit url for docs from existing value
1 parent e6869a5 commit 19a677f

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/helpers/edit-url-text.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
'use strict'
22

3+
const { posix: path } = require('path')
4+
35
module.exports = (page) => {
4-
if (page.attributes && page.attributes['edit-url-text']) return page.attributes['edit-url-text']
5-
return (page.attributes && page.attributes.theme === 'docs') ? 'Raise an issue' : 'Edit this page'
6+
const HOSTED_GIT_REPO_RX = /^(?:https?:\/\/|.+@)(git(?:hub|lab)\.com|bitbucket\.org|pagure\.io)[/:](.+?)(?:\.git)?$/
7+
const repoPage = page.attributes['edit-url-repo-action'] || 'issues'
8+
const repoExtra = repoPage === 'issues' ? 'new' : ''
9+
const feedbackTitle = page.attributes['edit-url-title'] || 'Docs Feedback'
10+
const feedbackLabels = page.attributes['edit-url-labels'] || ''
11+
12+
// text for the link is based on the edit-url-text attribute, or page theme
13+
const text = (page.attributes && page.attributes['edit-url-text'])
14+
? page.attributes['edit-url-text']
15+
: (page.attributes && page.attributes.theme === 'docs')
16+
? 'Raise an issue'
17+
: 'Edit this page'
18+
19+
// url for docs can be derived from page.editUrl
20+
// and updated to link to the repo issues page
21+
// for other themes, page.editUrl is used
22+
let url = page.editUrl
23+
if (page.attributes && page.attributes.theme === 'docs') {
24+
const match = url.match(HOSTED_GIT_REPO_RX)
25+
const editDetails = match[2].split('/')
26+
let query = `?title=${feedbackTitle}: ${path.join(...editDetails.slice(4))} (ref: ${editDetails[3]})`
27+
query += feedbackLabels !== '' ? `&labels=${feedbackLabels}` : ''
28+
url = 'https://' + path.join(match[1], editDetails[0], editDetails[1], repoPage, repoExtra, query)
29+
}
30+
31+
return {
32+
text: text,
33+
url: encodeURI(url),
34+
}
635
}

src/partials/edit-this-page-link.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{{#if (and page.fileUri (not env.CI))}}
33
<div class="edit-this-page"><a href="{{page.fileUri}}">Edit this Page</a></div>
44
{{else if (and page.editUrl (or env.FORCE_SHOW_EDIT_PAGE_LINK (not page.origin.private)))}}
5-
<div class="edit-this-page"><a href="{{page.editUrl}}">{{#with (edit-url-text page)}}{{{this}}}{{/with}}</a></div>
5+
{{#with (edit-url-text page)}}
6+
<div class="edit-this-page"><a href="{{{this.url}}}">{{{this.text}}}</a></div>
7+
{{/with}}
68
{{/if}}
79
{{/unless}}

0 commit comments

Comments
 (0)