From e6869a549dcd9940c1401f24305db765ae9d7931 Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Mon, 17 Feb 2025 18:52:18 +0000 Subject: [PATCH 1/3] helper to choose edit this page link text --- src/helpers/edit-url-text.js | 6 ++++++ src/partials/edit-this-page-link.hbs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/helpers/edit-url-text.js diff --git a/src/helpers/edit-url-text.js b/src/helpers/edit-url-text.js new file mode 100644 index 00000000..197bd541 --- /dev/null +++ b/src/helpers/edit-url-text.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = (page) => { + if (page.attributes && page.attributes['edit-url-text']) return page.attributes['edit-url-text'] + return (page.attributes && page.attributes.theme === 'docs') ? 'Raise an issue' : 'Edit this page' +} diff --git a/src/partials/edit-this-page-link.hbs b/src/partials/edit-this-page-link.hbs index e4b5c2bc..dbaac569 100644 --- a/src/partials/edit-this-page-link.hbs +++ b/src/partials/edit-this-page-link.hbs @@ -2,6 +2,6 @@ {{#if (and page.fileUri (not env.CI))}}
Edit this Page
{{else if (and page.editUrl (or env.FORCE_SHOW_EDIT_PAGE_LINK (not page.origin.private)))}} -
Edit this Page
+
{{#with (edit-url-text page)}}{{{this}}}{{/with}}
{{/if}} {{/unless}} \ No newline at end of file From 19a677fec927cbb22e6a2e6ae635fd5f4e65e0e7 Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Tue, 18 Feb 2025 20:10:10 +0000 Subject: [PATCH 2/3] derive a new edit url for docs from existing value --- src/helpers/edit-url-text.js | 33 ++++++++++++++++++++++++++-- src/partials/edit-this-page-link.hbs | 4 +++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/helpers/edit-url-text.js b/src/helpers/edit-url-text.js index 197bd541..3a65527c 100644 --- a/src/helpers/edit-url-text.js +++ b/src/helpers/edit-url-text.js @@ -1,6 +1,35 @@ 'use strict' +const { posix: path } = require('path') + module.exports = (page) => { - if (page.attributes && page.attributes['edit-url-text']) return page.attributes['edit-url-text'] - return (page.attributes && page.attributes.theme === 'docs') ? 'Raise an issue' : 'Edit this page' + const HOSTED_GIT_REPO_RX = /^(?:https?:\/\/|.+@)(git(?:hub|lab)\.com|bitbucket\.org|pagure\.io)[/:](.+?)(?:\.git)?$/ + const repoPage = page.attributes['edit-url-repo-action'] || 'issues' + const repoExtra = repoPage === 'issues' ? 'new' : '' + const feedbackTitle = page.attributes['edit-url-title'] || 'Docs Feedback' + const feedbackLabels = page.attributes['edit-url-labels'] || '' + + // text for the link is based on the edit-url-text attribute, or page theme + const text = (page.attributes && page.attributes['edit-url-text']) + ? page.attributes['edit-url-text'] + : (page.attributes && page.attributes.theme === 'docs') + ? 'Raise an issue' + : 'Edit this page' + + // url for docs can be derived from page.editUrl + // and updated to link to the repo issues page + // for other themes, page.editUrl is used + let url = page.editUrl + if (page.attributes && page.attributes.theme === 'docs') { + const match = url.match(HOSTED_GIT_REPO_RX) + const editDetails = match[2].split('/') + let query = `?title=${feedbackTitle}: ${path.join(...editDetails.slice(4))} (ref: ${editDetails[3]})` + query += feedbackLabels !== '' ? `&labels=${feedbackLabels}` : '' + url = 'https://' + path.join(match[1], editDetails[0], editDetails[1], repoPage, repoExtra, query) + } + + return { + text: text, + url: encodeURI(url), + } } diff --git a/src/partials/edit-this-page-link.hbs b/src/partials/edit-this-page-link.hbs index dbaac569..a5acf1a9 100644 --- a/src/partials/edit-this-page-link.hbs +++ b/src/partials/edit-this-page-link.hbs @@ -2,6 +2,8 @@ {{#if (and page.fileUri (not env.CI))}} {{else if (and page.editUrl (or env.FORCE_SHOW_EDIT_PAGE_LINK (not page.origin.private)))}} - + {{#with (edit-url-text page)}} + + {{/with}} {{/if}} {{/unless}} \ No newline at end of file From 822dae3cb2ddcaa6547e20fc63275b8b5620c9bc Mon Sep 17 00:00:00 2001 From: Neil Dewhurst Date: Mon, 24 Feb 2025 13:00:59 +0000 Subject: [PATCH 3/3] Add body, fix query params --- preview-src/tables.adoc | 4 ++++ src/helpers/edit-url-text.js | 31 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/preview-src/tables.adoc b/preview-src/tables.adoc index 6a66d27a..775e29ff 100644 --- a/preview-src/tables.adoc +++ b/preview-src/tables.adoc @@ -1,6 +1,10 @@ = Tables :nofooter: +:page-theme: docs :page-ogtitle: This page uses the page-ogtitle attribute to generate a custom title for SEO meta +// :page-edit-url-body: Custom raise an issue body text +// :page-edit-url-title: Custom raise an issue title text +:page-edit-url-uri: https://github.com/neo4j/docs-cypher/blob/dev/modules/ROOT/pages/queries/index.adoc .No striping // Alternative to stripes attributes is diff --git a/src/helpers/edit-url-text.js b/src/helpers/edit-url-text.js index 3a65527c..a7de96f4 100644 --- a/src/helpers/edit-url-text.js +++ b/src/helpers/edit-url-text.js @@ -7,7 +7,9 @@ module.exports = (page) => { const repoPage = page.attributes['edit-url-repo-action'] || 'issues' const repoExtra = repoPage === 'issues' ? 'new' : '' const feedbackTitle = page.attributes['edit-url-title'] || 'Docs Feedback' + const feedbackBody = page.attributes['edit-url-body'] || '> Do not include confidential information, personal data, sensitive data, or other regulated data.' const feedbackLabels = page.attributes['edit-url-labels'] || '' + let url = page.attributes['edit-url-uri'] || page.editUrl // text for the link is based on the edit-url-text attribute, or page theme const text = (page.attributes && page.attributes['edit-url-text']) @@ -19,13 +21,30 @@ module.exports = (page) => { // url for docs can be derived from page.editUrl // and updated to link to the repo issues page // for other themes, page.editUrl is used - let url = page.editUrl - if (page.attributes && page.attributes.theme === 'docs') { - const match = url.match(HOSTED_GIT_REPO_RX) + const match = url.match(HOSTED_GIT_REPO_RX) + if (page.attributes && page.attributes.theme === 'docs' && match) { const editDetails = match[2].split('/') - let query = `?title=${feedbackTitle}: ${path.join(...editDetails.slice(4))} (ref: ${editDetails[3]})` - query += feedbackLabels !== '' ? `&labels=${feedbackLabels}` : '' - url = 'https://' + path.join(match[1], editDetails[0], editDetails[1], repoPage, repoExtra, query) + const issueParts = { + title: { + text: feedbackTitle, + path: editDetails.slice(4) ? path.join(...editDetails.slice(4)) : '', + ref: editDetails[3] ? `(ref: ${editDetails[3]})` : '', + }, + query: { + body: feedbackBody !== '' ? feedbackBody : '', + labels: feedbackLabels !== '' ? feedbackLabels : '', + }, + } + + // construct issue content + const issueTitle = '?title=' + Object.values(issueParts.title).join(' ') + + // construct query params + const issueQuery = Object.keys(issueParts.query).map((key) => { + if (issueParts.query[key] !== '') return `&${key}=${issueParts.query[key]}` + }).join('') + + url = 'https://' + path.join(match[1], editDetails[0], editDetails[1], repoPage, repoExtra, issueTitle + issueQuery) } return {