合并两个单独的GatsbyJS入门主题

时间:2019-05-28 13:14:24

标签: javascript html reactjs graphql gatsby

我基本上是在尝试将gatsby-starter-ghost博客模板与另一个名为gatsby-serif-theme的静态站点模板集成。

我在做一些事情。

  1. 如何将两个不同的gatsby-config.js文件集成在一起?一世 在这里遇到很多错误(我粘贴了合并的 此电子邮件中下面的gatsby-config.js文件内容。)

  2. 我能够将两个项目的package.json文件缝合在一起而没有太大问题。还在下面发布了package.json的内容。

  3. 我还能够在以下位置创建一个名为“博客”的新文件夹。     我现有的gatsby-serif-themes静态站点的src / pages文件夹

  4. 两个主题在GraphQL中都有自己的架构。

    是否有规定的方法可以进行这种集成?

将两个主题组合在一起的配置更改数量可能会非常具有挑战性,尤其是当您同时在两个配置文件中都拥有gatsby-config.js,gatsby-browser.js和gatsby-node.js,netlify.toml等配置文件时模板等。

任何朝着正确方向的指针将受到高度赞赏。

错误:

  

错误尝试加载您站点的gatsby-config时遇到错误。 TypeError:无法解构“未定义”或“空”的属性apiUrl。

/** gatsbyconfig.js **/

const guid = process.env.NETLIFY_GOOGLE_ANALYTICS_ID;
const path = require(path)

const config = require(./src/utils/siteConfig)
const generateRSSFeed = require(./src/utils/rss/generate-feed)

let ghostConfig

try {
    ghostConfig = require(./.ghost)
} catch (e) {
    ghostConfig = {
        production: {
            apiUrl: process.env.GHOST_API_URL,
            contentApiKey: process.env.GHOST_CONTENT_API_KEY,
        },
    }
} finally {
    const { apiUrl, contentApiKey } = process.env.NODE_ENV === development ? ghostConfig.development : ghostConfig.production

    if (!apiUrl || !contentApiKey || contentApiKey.match(/<key>/)) {
        throw new Error(GHOST_API_URL and GHOST_CONTENT_API_KEY are required to build. Check the README.) // eslint-disable-line
    }
}

module.exports = {
    siteMetadata: {
        title: ‘Technovature Software’,
        description: ‘Next Generation Innovation’,
        contact: {
            phone: ‘+91 7013175234’,
            email: ‘info@technovature.com’,
            address: ‘Hyderabad’,
        },
        menuLinks: [{
                name: ‘Services’,
                link: ‘/services’,
            }, {
                name: ‘OUR WORK’,
                link: ‘/work’,
            }, {
                name: ‘About’,
                link: ‘/about’,
            }, {
                name: ‘Blog’,
                link: ‘/blog’,
            }, {
                name: ‘Testimonials’,
                link: ‘/testimonials’,
            }, {
                name: ‘Contact’,
                link: ‘/contact’,
            },
        ],
    },
    plugins: [
        ‘gatsby-plugin-sass’,
        ‘gatsby-transformer-json’,
        ‘gatsby-transformer-remark’,
        ‘gatsby-plugin-react-helmet’,
        {
            resolve: ‘gatsby-source-filesystem’,
            options: {
                path: ${dirname}/src/pages,
                name: ‘pages’,
            },
        }, {
            resolve: ‘gatsby-source-filesystem’,
            options: {
                path: ${dirname}/src/data,
                name: ‘data’,
            },
        }, {
            resolve: ‘gatsby-source-filesystem’,
            options: {
                path: ${__dirname}/src/images,
                name: ‘images’,
            },
        }, {
        resolve: ‘gatsby-plugin-google-analytics’,
        options: {
            trackingId: guid ? guid : ‘UA-XXX-1’,
            // Puts tracking script in the head instead of the body
            head: false,
            },
        },
        gatsby-plugin-sharp,
        gatsby-transformer-sharp,
        {
            resolve: gatsby-source-ghost,
            options:
                process.env.NODE_ENV === development
                    ? ghostConfig.development
                    : ghostConfig.production,
        },
        /** Utility Plugins */ 
        { resolve: gatsby-plugin-ghost-manifest, options: { short_name: config.shortTitle, start_url: /, background_color: config.backgroundColor, theme_color: config.themeColor, display: minimal-ui, icon: static/${config.siteIcon}, query: { allGhostSettings { edges { node { title description } } } }, }, }, { resolve: gatsby-plugin-feed, options: { query: { allGhostSettings { edges { node { title description } } } }, feeds: [ generateRSSFeed(config), ], }, }, { resolve: gatsby-plugin-advanced-sitemap, options: { query: { allGhostPost { edges { node { id slug updated_at created_at feature_image } } } allGhostPage { edges { node { id slug updated_at created_at feature_image } } } allGhostTag { edges { node { id slug feature_image } } } allGhostAuthor { edges { node { id slug profile_image } } } }, mapping: { allGhostPost: { sitemap: posts, }, allGhostTag: { sitemap: tags, }, allGhostAuthor: { sitemap: authors, }, allGhostPage: { sitemap: pages, }, }, exclude: [ /dev-404-page, /404, /404.html, /offline-plugin-app-shell-fallback, ], createLinkInHead: true, }, }, gatsby-plugin-force-trailing-slashes, gatsby-plugin-offline,
    ],
};


/** package.json file contents **/


{
  "name": "gatsby-serif-theme",
  "version": "1.0.0",
  "author": "Robert Austin <rob@jugglerdigital.com>",
  "license": "MIT",
  "scripts": {
    "develop": "gatsby develop",
    "start": "npm run develop",
    "build": "gatsby build",
    "now-build": "npm run build",
    "serve": "gatsby serve",
    "lint": "eslint . --ext .js --cache",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "dependencies": {
    "@tryghost/helpers": "1.1.3",
    "@tryghost/helpers-gatsby": "1.0.6",
    "cheerio": "1.0.0-rc.3",
    "@material-ui/core": "^3.9.3",
    "core-js": "^3.1.2",
    "gatsby": "^2.0.33",
    "gatsby-awesome-pagination": "0.3.4",
    "gatsby-image": "2.1.0",
    "gatsby-plugin-advanced-sitemap": "1.0.6",
    "gatsby-plugin-feed": "2.2.0",
    "gatsby-plugin-force-trailing-slashes": "1.0.4",
    "gatsby-plugin-manifest": "2.1.1",
    "gatsby-plugin-offline": "2.1.1",
    "gatsby-plugin-google-analytics": "^2.0.14",
    "gatsby-plugin-react-helmet": "^3.0.4",
    "gatsby-plugin-sass": "^2.0.7",
    "gatsby-plugin-sharp": "2.0.37",
    "gatsby-source-ghost": "3.3.2",
    "gatsby-transformer-sharp": "2.1.19",
    "lodash": "4.17.11",
    "gatsby-source-filesystem": "^2.0.12",
    "gatsby-transformer-json": "^2.1.6",
    "gatsby-transformer-remark": "^2.1.15",
    "google-map-react": "^1.1.4",
    "google-maps-react": "^2.0.2",
    "material-ui": "^0.20.2",
    "node-sass": "^4.11.0",
    "react": "^16.5.1",
    "react-dom": "^16.8.6",
    "react-helmet": "^5.2.0"
  },
  "devDependencies": {
    "babel-eslint": "^9.0.0",
    "eslint": "^5.5.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-ghost": "0.2.0",
    "eslint-plugin-jsx-a11y": "^6.1.1",
    "eslint-plugin-prettier": "^2.0.1",
    "eslint-plugin-react": "^7.11.1",
    "prettier-eslint": "^8.8.2"
  }
}

/** gatsby-node.js file contents **/

const path = require('path');

// Create pages from markdown files
exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions;
  return new Promise((resolve, reject) => {
    resolve(
      graphql(
        `
          query {
            services: allMarkdownRemark(
              filter: { fileAbsolutePath: { regex: "/services/" } }
              sort: { fields: [frontmatter___date], order: DESC }
            ) {
              edges {
                node {
                  id
                  frontmatter {
                    path
                    title
                    date(formatString: "DD MMMM YYYY")
                  }
                  excerpt
                }
              }
            }
            team: allMarkdownRemark(
              filter: { fileAbsolutePath: { regex: "/team/" } }
              sort: { fields: [frontmatter___date], order: DESC }
            ) {
              edges {
                node {
                  id
                  frontmatter {
                    path
                    title
                    date(formatString: "DD MMMM YYYY")
                  }
                  excerpt
                }
              }
            }
            testimonials: allMarkdownRemark(
              filter: { fileAbsolutePath: { regex: "/testimonials/" } }
              sort: { fields: [frontmatter___date], order: DESC }
            ) {
              edges {
                node {
                  id
                  frontmatter {
                    path
                    title
                    date(formatString: "DD MMMM YYYY")
                  }
                  excerpt
                }
              }
            }
          }
        `,
      ).then((result) => {
        result.data.services.edges.forEach(({ node }) => {
          const component = path.resolve('src/templates/service.js');
          createPage({
            path: node.frontmatter.path,
            component,
            context: {
              id: node.id,
            },
          });
        });
        result.data.team.edges.forEach(({ node }) => {
          const component = path.resolve('src/templates/team.js');
          createPage({
            path: node.frontmatter.path,
            component,
            context: {
              id: node.id,
            },
          });
        });
        result.data.testimonials.edges.forEach(({ node }) => {
          const component = path.resolve('src/templates/testimonial.js');
          createPage({
            path: node.frontmatter.path,
            component,
            context: {
              id: node.id,
            },
          });
        });
        resolve();
      }),
    );
  });
};


0 个答案:

没有答案