You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gatsby-node.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. const path = require('path');
  21. const fs = require('fs-extra');
  22. const { createFilePath } = require('gatsby-source-filesystem');
  23. exports.onCreateNode = ({ node, getNode, actions }) => {
  24. const { createNodeField } = actions;
  25. if (node.internal.type === 'MarkdownRemark') {
  26. const slug = createFilePath({ node, getNode, basePath: 'pages' });
  27. createNodeField({
  28. node,
  29. name: 'slug',
  30. value: slug
  31. });
  32. }
  33. };
  34. exports.createPages = ({ graphql, actions }) => {
  35. const { createPage } = actions;
  36. return new Promise((resolve, reject) => {
  37. graphql(`
  38. {
  39. allMarkdownRemark {
  40. edges {
  41. node {
  42. frontmatter {
  43. url
  44. }
  45. headings {
  46. depth
  47. value
  48. }
  49. fields {
  50. slug
  51. }
  52. }
  53. }
  54. }
  55. }
  56. `).then(result => {
  57. result.data.allMarkdownRemark.edges.forEach(({ node }) => {
  58. createPage({
  59. path: node.frontmatter.url || node.fields.slug,
  60. component: path.resolve('./src/templates/page.tsx'),
  61. context: {
  62. // Data passed to context is available in page queries as GraphQL variables.
  63. slug: node.fields.slug
  64. }
  65. });
  66. });
  67. resolve();
  68. });
  69. });
  70. };
  71. exports.onPostBootstrap = () => {
  72. const from = path.resolve(__dirname, 'src/images');
  73. const to = path.resolve(__dirname, 'public/images');
  74. return fs.copy(from, to);
  75. };