]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11307 Enhance embedded documentation with nav metadata
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Thu, 25 Oct 2018 12:27:13 +0000 (14:27 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 30 Oct 2018 11:42:04 +0000 (12:42 +0100)
18 files changed:
server/sonar-docs/src/__tests__/BrokenLinkSafetyNet.test.js
server/sonar-docs/src/layouts/components/CategoryLink.js
server/sonar-docs/src/layouts/components/SubpageLink.js
server/sonar-docs/src/layouts/index.js
server/sonar-docs/src/pages/404.md
server/sonar-web/src/main/js/apps/documentation/components/MenuItem.tsx
server/sonar-web/src/main/js/apps/documentation/components/__tests__/Menu-test.tsx
server/sonar-web/src/main/js/apps/documentation/components/__tests__/MenuBlock-test.tsx
server/sonar-web/src/main/js/apps/documentation/components/__tests__/SearchResultEntry-test.tsx
server/sonar-web/src/main/js/apps/documentation/components/__tests__/SearchResults-test.tsx
server/sonar-web/src/main/js/apps/documentation/components/__tests__/Sidebar-test.tsx
server/sonar-web/src/main/js/apps/documentation/components/__tests__/__snapshots__/Menu-test.tsx.snap
server/sonar-web/src/main/js/apps/documentation/components/__tests__/__snapshots__/MenuBlock-test.tsx.snap
server/sonar-web/src/main/js/apps/documentation/components/__tests__/__snapshots__/SearchResultEntry-test.tsx.snap
server/sonar-web/src/main/js/apps/documentation/components/__tests__/__snapshots__/SearchResults-test.tsx.snap
server/sonar-web/src/main/js/apps/documentation/components/__tests__/__snapshots__/Sidebar-test.tsx.snap
server/sonar-web/src/main/js/apps/documentation/pages.ts
server/sonar-web/src/main/js/apps/documentation/utils.ts

index 91a47bc91a439e4362cd3fdeef2675d0894539d4..fdf2a42ad3726e5800ec92ade13a7b1742f23e6b 100644 (file)
@@ -33,6 +33,15 @@ beforeAll(async () => {
   });
 });
 
+it('should have at least one instance of all possible frontmatter fields', () => {
+  let pageWithTitle = parsedFiles.find(file => file.frontmatter.title !== undefined);
+  let pageWithNav = parsedFiles.find(file => file.frontmatter.nav !== undefined);
+  let pageWithUrl = parsedFiles.find(file => file.frontmatter.url !== undefined);
+  expect(pageWithTitle).toBeDefined();
+  expect(pageWithNav).toBeDefined();
+  expect(pageWithUrl).toBeDefined();
+});
+
 it('should have valid links in trees files', () => {
   const trees = [
     'SonarCloudNavigationTree.json',
index aa3ef073347cf96a8a4197b84608ad94a89549c8..de708652ad072908d17aeec8c57fab36dccba5f5 100644 (file)
@@ -41,14 +41,15 @@ export default class CategoryLink extends React.PureComponent {
     const prefix = process.env.GATSBY_DOCS_VERSION ? '/' + process.env.GATSBY_DOCS_VERSION : '';
     const url = node ? node.frontmatter.url || node.fields.slug : '';
     const isCurrentPage = location.pathname === prefix + url;
+    const linkTitle = node ? node.frontmatter.nav || node.frontmatter.title : '';
     return (
       <div>
         {node ? (
           <Link
             className={isCurrentPage || open ? 'page-indexes-link active' : 'page-indexes-link'}
             to={url}
-            title={node.frontmatter.title}>
-            {node.frontmatter.title}
+            title={linkTitle}>
+            {linkTitle}
           </Link>
         ) : (
           <a
index c0027e3ed760bfb1ddc205fa6bcb7255fcf24e11..f3977b21be33911ca0e5707f8de62879712ac7b9 100644 (file)
@@ -22,10 +22,11 @@ import Link from 'gatsby-link';
 import HeadingsLink from './HeadingsLink';
 
 export default function SubpageLink({ node, active }) {
+  const linkTitle = node.frontmatter.nav || node.frontmatter.title;
   return (
     <div>
       <Link className={active ? 'sub-menu-link active' : 'sub-menu-link'} to={node.fields.slug}>
-        {node.frontmatter.title}
+        {linkTitle}
       </Link>
     </div>
   );
index a65714c59c243246ec9870e42ac0fcf2e3ee643d..fe7a97cf4c57a826346a351756c21c8b0c347cc9 100644 (file)
@@ -69,6 +69,7 @@ export const query = graphql`
           }
           frontmatter {
             title
+            nav
             url
           }
           fields {
index d6a0f85fd7ec7b534b0156e0d43cf327f4b28c9a..ef227477acbdebfaf8dd25eeefdb4bacf0c68af3 100644 (file)
@@ -1,5 +1,6 @@
 ---
 title: Page not found
+nav: Not found
 url: /404/
 ---
 
index 0b67f4d704508c71d8b2470bca2ae512a944befe..9c375d5f3e7b62e68d8bbd49ff232dd437097a5a 100644 (file)
@@ -40,7 +40,7 @@ export function MenuItem({ indent, node, splat }: Props) {
       key={node.url}
       style={{ paddingLeft: indent ? 31 : 10 }}
       to={'/documentation' + node.url}>
-      <h3 className="list-group-item-heading">{node.title}</h3>
+      <h3 className="list-group-item-heading">{node.navTitle || node.title}</h3>
     </Link>
   );
 }
index 1985bc439f6a74e85ac559899947c32f6e58bf66..b0cddf170b39533df6c638fea446def39b712e47 100644 (file)
@@ -22,7 +22,7 @@ import { shallow } from 'enzyme';
 import Menu from '../Menu';
 
 function createPage(title: string, relativeName: string, text = '') {
-  return { relativeName, url: '/' + relativeName, title, text, content: text };
+  return { relativeName, url: '/' + relativeName, title, navTitle: undefined, text, content: text };
 }
 
 const pages = [
index 9dcfe4683354c3d13ef45ebf43d43af9304bcff4..0c09a83d9e6e28d721e253faabf24c3193e026d0 100644 (file)
@@ -32,6 +32,7 @@ const pages = [
     relativeName: '/bar/',
     text: 'bar',
     title: 'Bar',
+    navTitle: undefined,
     url: '/bar/'
   },
   {
@@ -39,6 +40,7 @@ const pages = [
     relativeName: '/baz/',
     text: 'baz',
     title: 'baz',
+    navTitle: 'baznav',
     url: '/baz/'
   }
 ];
index f38330cb5858c392b7ba7d967b77f45a048b51d4..abac582070994fad88912235fa8c3bace7334d82 100644 (file)
@@ -30,7 +30,8 @@ const page = {
   relativeName: 'foo/bar',
   url: '/foo/bar',
   text: 'Foobar is a universal variable understood to represent whatever is being discussed.',
-  title: 'Foobar'
+  title: 'Foobar',
+  navTitle: undefined
 };
 
 describe('SearchResultEntry', () => {
index be38eb5a2f6493f2eb55fdd23a47dea66624ac56..4c5dc23c5df626785dccbf7137721303a8afada3 100644 (file)
@@ -37,7 +37,7 @@ jest.mock('lunr', () => ({
 }));
 
 function createPage(title: string, relativeName: string, text = '') {
-  return { relativeName, url: '/' + relativeName, title, text, content: text };
+  return { relativeName, url: '/' + relativeName, title, navTitle: undefined, text, content: text };
 }
 
 const pages = [
index ab41a1a9afeca1a0c60c7989800157e35b335d6a..a30516ef71130808c2d02f4feca36923a206aefe 100644 (file)
@@ -22,7 +22,7 @@ import { shallow } from 'enzyme';
 import Sidebar from '../Sidebar';
 
 function createPage(title: string, relativeName: string, text = '') {
-  return { relativeName, url: '/' + relativeName, title, text, content: text };
+  return { relativeName, url: '/' + relativeName, title, navTitle: undefined, text, content: text };
 }
 
 const pages = [
index 469a3f41a6db1bab2c58b056723839f25a2a983b..ed2f0e728ea8518c05908190f8d8165b2019f195 100644 (file)
@@ -19,6 +19,7 @@ Array [
       Array [
         Object {
           "content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
+          "navTitle": undefined,
           "relativeName": "lorem/index",
           "text": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
           "title": "Lorem Ipsum",
@@ -26,6 +27,7 @@ Array [
         },
         Object {
           "content": "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words.",
+          "navTitle": undefined,
           "relativeName": "lorem/origin",
           "text": "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words.",
           "title": "Where does it come from?",
@@ -33,6 +35,7 @@ Array [
         },
         Object {
           "content": "Foobar is a universal variable understood to represent whatever is being discussed.",
+          "navTitle": undefined,
           "relativeName": "foobar",
           "text": "Foobar is a universal variable understood to represent whatever is being discussed.",
           "title": "Where does Foobar come from?",
index 9f08ac7b98b3a51f43d157dcef7bbdd8f6e0bee9..0ee9f2fbead34df91b45d120a4c9a101096de705 100644 (file)
@@ -43,6 +43,7 @@ exports[`should render an opened menu block 1`] = `
     node={
       Object {
         "content": "bar",
+        "navTitle": undefined,
         "relativeName": "/bar/",
         "text": "bar",
         "title": "Bar",
@@ -57,6 +58,7 @@ exports[`should render an opened menu block 1`] = `
     node={
       Object {
         "content": "baz",
+        "navTitle": "baznav",
         "relativeName": "/baz/",
         "text": "baz",
         "title": "baz",
index cc19cf2f4ffba50613f86b7de42bc8fad93dd836..40818733fe7a41dab6549b484a0fb634cf69132a 100644 (file)
@@ -14,6 +14,7 @@ exports[`SearchResultEntry should render 1`] = `
         "longestTerm": "",
         "page": Object {
           "content": "",
+          "navTitle": undefined,
           "relativeName": "foo/bar",
           "text": "Foobar is a universal variable understood to represent whatever is being discussed.",
           "title": "Foobar",
@@ -29,6 +30,7 @@ exports[`SearchResultEntry should render 1`] = `
         "longestTerm": "",
         "page": Object {
           "content": "",
+          "navTitle": undefined,
           "relativeName": "foo/bar",
           "text": "Foobar is a universal variable understood to represent whatever is being discussed.",
           "title": "Foobar",
index 2abdbd1e2cafe3a643470dbc775e8bd65b0c2fc6..4a79799119b75e6bff20d6b8cd8138bc07ef4e2f 100644 (file)
@@ -24,6 +24,7 @@ exports[`should search 1`] = `
         "longestTerm": "from",
         "page": Object {
           "content": "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words.",
+          "navTitle": undefined,
           "relativeName": "lorem/origin",
           "text": "Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words.",
           "title": "Where does it come from?",
@@ -48,6 +49,7 @@ exports[`should search 1`] = `
         "longestTerm": "from",
         "page": Object {
           "content": "Foobar is a universal variable understood to represent whatever is being discussed.",
+          "navTitle": undefined,
           "relativeName": "foobar",
           "text": "Foobar is a universal variable understood to represent whatever is being discussed.",
           "title": "Where does Foobar come from?",
index 7e7444143b4c1266f6201a07acc839dfeb37edc7..0b051b98546bcbca68578e44937d9ee761d3c5df 100644 (file)
@@ -31,6 +31,7 @@ exports[`should render menu 1`] = `
           Array [
             Object {
               "content": "",
+              "navTitle": undefined,
               "relativeName": "lorem/index",
               "text": "",
               "title": "Lorem Ipsum",
@@ -38,6 +39,7 @@ exports[`should render menu 1`] = `
             },
             Object {
               "content": "",
+              "navTitle": undefined,
               "relativeName": "foobar",
               "text": "",
               "title": "Where does Foobar come from?",
@@ -83,6 +85,7 @@ exports[`should search 1`] = `
           Array [
             Object {
               "content": "",
+              "navTitle": undefined,
               "relativeName": "lorem/index",
               "text": "",
               "title": "Lorem Ipsum",
@@ -90,6 +93,7 @@ exports[`should search 1`] = `
             },
             Object {
               "content": "",
+              "navTitle": undefined,
               "relativeName": "foobar",
               "text": "",
               "title": "Where does Foobar come from?",
index 7aea76e867c6732bb854b660b041f874e099777d..4c94af0c3a06e1e74348e1c3cb64bc07fb4be821 100644 (file)
@@ -33,6 +33,7 @@ export default function getPages(): DocumentationEntry[] {
       relativeName: file.path,
       url: parsed.frontmatter.url || `/${file.path}`,
       title: parsed.frontmatter.title,
+      navTitle: parsed.frontmatter.nav || undefined,
       order: Number(parsed.frontmatter.order || -1),
       scope: parsed.frontmatter.scope
         ? (parsed.frontmatter.scope.toLowerCase() as DocumentationEntryScope)
index 3c08b6a26b4b0c5d0503194d10283a727b921f86..5f82f3dce9a93d92442f13c6cd84e0190802b542 100644 (file)
@@ -34,6 +34,7 @@ export interface DocsNavigationExternalLink {
 export interface DocumentationEntry {
   content: string;
   relativeName: string;
+  navTitle: string | undefined;
   text: string;
   title: string;
   url: string;