From 3b303759f50075b1c1f4ac6222e9efcbb601f017 Mon Sep 17 00:00:00 2001 From: Alex S Date: Tue, 5 Sep 2017 10:26:20 +0200 Subject: [PATCH] chore(doc): fix edit links for reference API (#2303) * chore(doc): edit this page links now points to develop This might not be in sync with the current content but those will be the current next version. * chore(doc): fix edit links for reference API The script was assuming the name of the repo would be `instantsearch.js` which might be an issue if the name of the folder is different. Also refactor the way we figure out the path of each file because there was a discrepancy. FIX #2301 --- .../layouts/archetypes/content-with-menu.pug | 2 +- docgen/plugins/documentationjs-data.js | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docgen/layouts/archetypes/content-with-menu.pug b/docgen/layouts/archetypes/content-with-menu.pug index 528e5f1e49..a32efb4e46 100644 --- a/docgen/layouts/archetypes/content-with-menu.pug +++ b/docgen/layouts/archetypes/content-with-menu.pug @@ -10,7 +10,7 @@ body.documentation a.sidebar-opener .documentation-container if(editable) - a.editThisPage(href=`http://github.com/algolia/instantsearch.js/edit/master/${githubSource}`) Edit this page + a.editThisPage(href=`http://github.com/algolia/instantsearch.js/edit/develop/${githubSource}`) Edit this page block content include ../common/footer.pug diff --git a/docgen/plugins/documentationjs-data.js b/docgen/plugins/documentationjs-data.js index 9de4f25c9e..5bf761598e 100644 --- a/docgen/plugins/documentationjs-data.js +++ b/docgen/plugins/documentationjs-data.js @@ -1,8 +1,15 @@ +import path from 'path'; + import {uniqBy, forEach, reduce, groupBy, findIndex, find, filter, isArray, isObject} from 'lodash'; import documentation from 'documentation'; import remark from 'remark'; import md from '../mdRenderer'; +const baseDir = path.resolve(process.cwd(), '..'); +function getGithubSource(symbol) { + return symbol.context.file.split(baseDir)[1].substring(1); +} + function formatMD(ast) { if (ast && ast.type === 'root') { // 1. extract the raw markdown string from the remark AST @@ -82,8 +89,6 @@ function groupSymbolsByCategories(symbols) { function mapInstantSearch([instantsearchFactory, InstantSearch], symbols, files) { const fileName = 'instantsearch.html'; - const githubSource = InstantSearch.context.file.split('instantsearch.js')[1]; - files[fileName] = { mode: '0764', contents: '', @@ -101,7 +106,7 @@ function mapInstantSearch([instantsearchFactory, InstantSearch], symbols, files) }, withHeadings: true, editable: true, - githubSource: githubSource, + githubSource: getGithubSource(InstantSearch), }; } @@ -114,9 +119,6 @@ function mapConnectors(connectors, symbols, files) { relatedTypes: findRelatedTypes(symbol, symbols), }; - const githubSource = 'http://github.com/algolia/instantsearch.js/edit/master' + - symbolWithRelatedType.context.file.split('instantsearch.js')[1]; - files[fileName] = { mode: '0764', contents: '', @@ -128,7 +130,7 @@ function mapConnectors(connectors, symbols, files) { jsdoc: symbolWithRelatedType, withHeadings: true, editable: true, - githubSource: githubSource, + githubSource: getGithubSource(symbolWithRelatedType), }; }); } @@ -146,8 +148,6 @@ function mapWidgets(widgets, symbols, files) { relatedTypes, }; - const githubSource = symbolWithRelatedType.context.file.split('instantsearch.js/')[1]; - files[fileName] = { mode: '0764', contents: '', @@ -159,7 +159,7 @@ function mapWidgets(widgets, symbols, files) { jsdoc: symbolWithRelatedType, withHeadings: true, editable: true, - githubSource: githubSource, + githubSource: getGithubSource(symbolWithRelatedType), }; }); }