Skip to content

Commit

Permalink
feat: Upgrade core docs tech from sentry-docs
Browse files Browse the repository at this point in the history
- Move to typescript
- Update directory structure
- Update code tabs plugin
- Pull in various common components
  • Loading branch information
dcramer committed Oct 21, 2020
1 parent 57911cc commit f0cbf8b
Show file tree
Hide file tree
Showing 58 changed files with 2,478 additions and 986 deletions.
8 changes: 7 additions & 1 deletion gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from "react";
import PageContext from "~src/components/pageContext";

export const wrapPageElement = ({ element, props: { pageContext } }) => (
<PageContext.Provider value={pageContext}>{element}</PageContext.Provider>
);

// Disable prefetching altogether so our bw is not destroyed.
// If this turns out to hurt performance significantly, we can
// try out https://www.npmjs.com/package/gatsby-plugin-guess-js
// with data from the prior 1-2 weeks.
export const disableCorePrefetching = () => true;

142 changes: 11 additions & 131 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// const path = require("path");
require("ts-node").register({
files: true, // to that TS node hooks have access to local typings too
});

const activeEnv =
process.env.GATSBY_ENV || process.env.NODE_ENV || "development";

Expand All @@ -8,134 +11,11 @@ require("dotenv").config({
path: `.env.${activeEnv}`,
});

const queries = require("./src/utils/algolia");

const getPlugins = () => {
const plugins = [
{
resolve: "@sentry/gatsby",
options: {
dsn:
process.env.SENTRY_DSN ||
"https://[email protected]/5266138",
tracesSampleRate: activeEnv === "development" ? 0 : 1,
},
},
"gatsby-plugin-sass",
"gatsby-plugin-sharp",
"gatsby-plugin-zeit-now",
{
resolve: "gatsby-plugin-google-gtag",
options: {
// You can add multiple tracking ids and a pageview event will be fired for all of them.
trackingIds: [
"UA-30327640-1", // Sentry
],
// This object gets passed directly to the gtag config command
// This config will be shared across all trackingIds
gtagConfig: {
anonymize_ip: true,
cookie_expires: 0,
},
},
},
{
resolve: "gatsby-plugin-mdx",
options: {
remarkPlugins: [require("remark-deflist")],
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-copy-linked-files`,
},
{
resolve: `gatsby-remark-autolink-headers`,
options: {
className: "anchor",
icon: `<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M10.879 6.05L15 1.93A5.001 5.001 0 0 1 22.071 9l-4.121 4.121a1 1 0 0 1-1.414-1.414l4.12-4.121a3 3 0 1 0-4.242-4.243l-4.121 4.121a1 1 0 1 1-1.414-1.414zm2.242 11.9L9 22.07A5 5 0 1 1 1.929 15l4.121-4.121a1 1 0 0 1 1.414 1.414l-4.12 4.121a3 3 0 1 0 4.242 4.243l4.121-4.121a1 1 0 1 1 1.414 1.414zm-8.364-.122l13.071-13.07a1 1 0 0 1 1.415 1.414L6.172 19.242a1 1 0 1 1-1.415-1.414z" fill="currentColor"></path></svg>`,
enableCustomId: true,
},
},
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 1200,
linkImagesToOriginal: false,
},
},
{
resolve: "gatsby-remark-mermaid",
},
{
resolve: require.resolve("./plugins/gatsby-plugin-code-tabs"),
},
{
resolve: require.resolve("./plugins/gatsby-plugin-include"),
},
{
resolve: "gatsby-remark-prismjs",
options: {
noInlineHighlight: true,
},
},
{
resolve: `gatsby-remark-check-links`,
},
],
},
},
"gatsby-plugin-react-helmet",
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `docs`,
path: `${__dirname}/src/docs`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `pages`,
path: `${__dirname}/src/pages`,
},
},
{
resolve: require.resolve("./plugins/gatsby-plugin-jsonschema"),
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.app/offline
// 'gatsby-plugin-offline',
];
if (process.env.ALGOLIA_INDEX === "1") {
plugins.push({
resolve: `gatsby-plugin-algolia`,
options: {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.ALGOLIA_ADMIN_KEY,
queries,
chunkSize: 10000, // default: 1000
enablePartialUpdates: true,
matchFields: ["text", "section", "title", "url", "keywords"],
},
});
}
return plugins;
};
if (
process.env.VERCEL_GITHUB_COMMIT_REF === "master" &&
process.env.ALGOLIA_ADMIN_KEY
) {
process.env.ALGOLIA_INDEX = "1";
}

module.exports = {
// pathPrefix: `/develop`,
siteMetadata: {
title: "Sentry Developer Documentation",
homeUrl: "https://sentry.io",
sitePath: "develop.sentry.dev",
description: "Documentation for contributing to the Sentry project",
author: "@getsentry",
},
plugins: getPlugins(),
};
module.exports = require("./src/gatsby/config");
81 changes: 4 additions & 77 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,4 @@
const { createFilePath } = require("gatsby-source-filesystem");

exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;
if (
node.internal.type === "Mdx" &&
(!node.parent ||
getNode(node.parent).internal.type !== "JsonSchemaMarkdown")
) {
const value = createFilePath({ node, getNode });
createNodeField({
name: "slug",
node,
value,
});
}
};

exports.createPages = async function({ actions, graphql }) {
const { data, errors } = await graphql(`
query {
allFile {
nodes {
id
childMdx {
fields {
slug
}
frontmatter {
title
sidebar_order
}
}
}
}
}
`);

if (errors) {
reporter.panicOnBuild('🚨 ERROR: Loading "createPages" query');
}
const component = require.resolve(`./src/components/layout.js`);
data.allFile.nodes.forEach(node => {
if (node.childMdx && node.childMdx.fields) {
const child = node.childMdx;
actions.createPage({
path: child.fields.slug,
component,
context: {
id: node.id,
title: child.frontmatter.title,
sidebar_order: child.frontmatter.sidebar_order,
sidebar_title:
child.frontmatter.sidebar_title || child.frontmatter.title,
},
});
}
});
};

exports.createSchemaCustomization = ({ actions: { createTypes } }) => {
const typeDefs = `
type Mdx implements Node {
frontmatter: MdxFrontmatter
}
type MdxFrontmatter {
title: String
sidebar_order: Int
sidebar_title: String
keywords: [String]
description: String
}
`;

createTypes(typeDefs);
};
exports.onCreateNode = require("./src/gatsby/onCreateNode").default;
exports.onCreateWebpackConfig = require("./src/gatsby/onCreateWebpackConfig").default;
exports.createPages = require("./src/gatsby/createPages").default;
exports.createSchemaCustomization = require("./src/gatsby/createSchemaCustomization").default;
6 changes: 6 additions & 0 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import PageContext from "~src/components/pageContext";

export const wrapPageElement = ({ element, props: { pageContext } }) => (
<PageContext.Provider value={pageContext}>{element}</PageContext.Provider>
);
22 changes: 17 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
"name": "sentry-docs-develop",
"description": "",
"dependencies": {
"@emotion/core": "^10.0.35",
"@emotion/styled": "^10.0.27",
"@mdx-js/mdx": "^1.6.1",
"@mdx-js/react": "^1.6.1",
"@sentry/apm": "^5.20.0",
"@sentry/gatsby": "^5.20.0",
"@sentry/react": "^5.20.0",
"@sentry-internal/global-search": "^0.0.30",
"@sentry/gatsby": "^5.27.0",
"@sentry/tracing": "^5.27.0",
"@sentry/webpack-plugin": "^1.13.0",
"@types/dompurify": "^2.0.3",
"@types/node": "^12",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
"@types/react-helmet": "^6.1.0",
"@types/react-select": "^3.0.19",
"@untitaker/quicktype-core-with-markdown": "^6.0.69",
"add": "^2.0.6",
"algoliasearch": "^4.2.0",
Expand All @@ -16,14 +25,15 @@
"dotenv": "^8.2.0",
"gatsby": "^2.21.18",
"gatsby-image": "^2.4.3",
"gatsby-plugin-algolia": "^0.9.0",
"gatsby-plugin-algolia": "^0.11.2",
"gatsby-plugin-google-gtag": "^2.1.11",
"gatsby-plugin-manifest": "^2.4.2",
"gatsby-plugin-mdx": "^1.2.6",
"gatsby-plugin-offline": "^2.2.10",
"gatsby-plugin-react-helmet": "^3.3.1",
"gatsby-plugin-sass": "^2.3.1",
"gatsby-plugin-sharp": "^2.6.2",
"gatsby-plugin-typescript": "^2.4.18",
"gatsby-plugin-zeit-now": "^0.3.0",
"gatsby-remark-autolink-headers": "^2.3.1",
"gatsby-remark-check-links": "^2.1.0",
Expand All @@ -38,12 +48,14 @@
"prop-types": "^15.7.2",
"puppeteer": "^5.0.0",
"react": "^16.13.1",
"react-bootstrap": "^1.4.0",
"react-dom": "^16.13.1",
"react-feather": "^2.0.8",
"react-helmet": "^5.2.1",
"react-instantsearch-dom": "^6.4.0",
"remark-deflist": "^0.2.1",
"sentry-global-search": "getsentry/sentry-global-search#0.0.18"
"ts-node": "^9.0.0",
"typescript": "^3.9.7"
},
"keywords": [
"gatsby"
Expand Down
39 changes: 0 additions & 39 deletions src/components/alert.js

This file was deleted.

41 changes: 41 additions & 0 deletions src/components/alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";

type Props = {
title?: string;
level?: string;
deepLink?: string;
dismiss?: boolean;
children?: any;
};

export default ({
title,
children,
level,
deepLink,
dismiss = false,
}: Props): JSX.Element => {
let className = "alert";
if (level) {
className += ` alert-${level}`;
}
if (children.props && typeof children.props.children === "string") {
className += " markdown-text-only";
}
return (
<div className={className} role="alert" id={deepLink}>
{dismiss && (
<button
type="button"
className="close"
data-dismiss="alert"
aria-label="Close"
>
<span aria-hidden="true">&times;</span>
</button>
)}
{title && <h5 className="no_toc">{title}</h5>}
<div className="alert-body content-flush-bottom">{children}</div>
</div>
);
};
Loading

0 comments on commit f0cbf8b

Please sign in to comment.