diff --git a/preview-src/tables.adoc b/preview-src/tables.adoc index e45c503f..d6de6b90 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 :page-custom-canonical: https://neo4j.com/docs/cypher-manual/current/clauses/where/ .No striping diff --git a/src/helpers/edit-url-text.js b/src/helpers/edit-url-text.js new file mode 100644 index 00000000..a7de96f4 --- /dev/null +++ b/src/helpers/edit-url-text.js @@ -0,0 +1,54 @@ +'use strict' + +const { posix: path } = require('path') + +module.exports = (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 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']) + ? 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 + const match = url.match(HOSTED_GIT_REPO_RX) + if (page.attributes && page.attributes.theme === 'docs' && match) { + const editDetails = match[2].split('/') + 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 { + text: text, + url: encodeURI(url), + } +} diff --git a/src/partials/edit-this-page-link.hbs b/src/partials/edit-this-page-link.hbs index e4b5c2bc..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