Skip to content

Bug/fix small website issues #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { wrapRootElement } from "./src/@rocketseat/gatsby-theme-docs/gatsby/wrapRootElement";
export { wrapPageElement } from "./src/@rocketseat/gatsby-theme-docs/gatsby/wrapPageElement";
69 changes: 56 additions & 13 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,73 @@
const withDefault = require(`./src/@rocketseat/gatsby-theme-docs-core/util/with-default`);

const siteUrl = `https://golangci-lint.run`;

const siteConfig = require(`./src/config/site.js`);
const { basePath, configPath, docsPath } = withDefault(siteConfig);

module.exports = {
siteMetadata: {
siteTitle: `golangci-lint`,
defaultTitle: ``,
siteTitleShort: `golangci-lint`,
siteDescription: `Fast Go linters runner golangci-lint.`,
siteUrl: siteUrl,
siteUrl,
siteAuthor: `@golangci`,
siteImage: `/logo.png`,
siteLanguage: `en`,
themeColor: `#7159c1`,
basePath: `/`,
basePath,
footer: `© ${new Date().getFullYear()}`,
},
plugins: [
`gatsby-alias-imports`,

`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `docs`,
path: docsPath,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `config`,
path: configPath,
},
},
{
resolve: `gatsby-transformer-yaml`,
options: {
typeName: `SidebarItems`,
},
},
{
resolve: `@rocketseat/gatsby-theme-docs`,
resolve: `gatsby-plugin-mdx`,
options: {
configPath: `src/config`,
docsPath: `src/docs`,
githubUrl: `https://github.com/golangci/golangci-lint`,
baseDir: `docs`,
extensions: [`.mdx`, `.md`],
gatsbyRemarkPlugins: [
`gatsby-remark-autolink-headers`,
`gatsby-remark-external-links`,
`gatsby-remark-embedder`,
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 960,
withWebp: true,
linkImagesToOriginal: false,
},
},
`gatsby-remark-responsive-iframe`,
`gatsby-remark-copy-linked-files`,
],
plugins: [
`gatsby-remark-autolink-headers`,
`gatsby-remark-external-links`,
`gatsby-remark-images`,
],
},
},
{
Expand Down Expand Up @@ -59,13 +104,11 @@ module.exports = {
},
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [`gatsby-remark-external-links`],
},
},
`gatsby-plugin-netlify`,
`gatsby-plugin-netlify-cache`,

`gatsby-plugin-catch-links`,
`gatsby-plugin-emotion`,
`gatsby-plugin-react-helmet`,
],
};
252 changes: 252 additions & 0 deletions docs/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
const path = require(`path`);
const { createFilePath } = require(`gatsby-source-filesystem`);
const fs = require(`fs`);

const {
normalizeBasePath,
resolveLink,
} = require(`./src/@rocketseat/gatsby-theme-docs-core/util/url`);
const withDefault = require(`./src/@rocketseat/gatsby-theme-docs-core/util/with-default`);

exports.createPages = ({ graphql, actions: { createPage }, reporter }) => {
reporter.success(`onCreateDocs`);

const siteConfig = require(`./src/config/site.js`);
const { basePath, baseDir, docsPath, githubUrl } = withDefault(siteConfig);

const docsTemplate = require.resolve(
`./src/@rocketseat/gatsby-theme-docs/src/templates/docs-query.js`
);
const homeTemplate = require.resolve(
`./src/@rocketseat/gatsby-theme-docs/src/templates/homepage-query.js`
);

return graphql(
`
{
files: allFile(filter: { extension: { in: ["md", "mdx"] } }) {
edges {
node {
id
relativePath
childMdx {
frontmatter {
next
}
fields {
slug
}
}
}
}
}
sidebar: allSidebarItems {
edges {
node {
label
link
items {
label
link
}
id
}
}
}
}
`
).then((result) => {
if (result.errors) {
reporter.panic(
`docs: there was an error loading the docs folder!`,
result.errors
);
return;
}

createPage({
path: basePath,
component: homeTemplate,
});

// Generate prev/next items based on sidebar.yml file
const sidebar = result.data.sidebar.edges;
const listOfItems = [];

sidebar.forEach(({ node: { label, link, items } }) => {
if (Array.isArray(items)) {
items.forEach((item) => {
listOfItems.push({
label: item.label,
link: resolveLink(item.link, basePath),
});
});
} else {
listOfItems.push({
label,
link: resolveLink(link, basePath),
});
}
});

// Generate docs pages
const docs = result.data.files.edges;
docs.forEach((doc) => {
const {
childMdx: {
frontmatter: { next },
fields: { slug },
},
relativePath,
} = doc.node;

const githubEditUrl =
githubUrl &&
`${githubUrl}/tree/master/${baseDir}/${docsPath}/${relativePath}`;

const currentPageIndex = listOfItems.findIndex(
(page) => page.link === slug
);

const prevItem = listOfItems[currentPageIndex - 1];
const nextItem = next
? listOfItems.find((item) => item.link === next)
: listOfItems[currentPageIndex + 1];

createPage({
path: slug,
component: docsTemplate,
context: {
slug,
prev: prevItem,
next: nextItem,
githubEditUrl,
},
});
});

reporter.success(`docs pages created`);
});
};

exports.createSchemaCustomization = ({ actions }) => {
actions.createTypes(`
type MdxFrontmatter @dontInfer {
title: String!
description: String
image: String
disableTableOfContents: Boolean
next: String
}
`);

actions.createTypes(`
type SidebarItems implements Node {
label: String!
link: String
items: [SidebarItemsItems]
}

type SidebarItemsItems {
label: String
link: String
}
`);
};

exports.onPreBootstrap = ({ store, reporter }, themeOptions) => {
const { configPath, docsPath } = withDefault(themeOptions);
const { program } = store.getState();

const dirs = [
path.join(program.directory, configPath),
path.join(program.directory, docsPath),
];

dirs.forEach((dir) => {
if (!fs.existsSync(dir)) {
reporter.success(`docs: intialized the ${dir} directory`);
fs.mkdirSync(dir);
}
});
};

exports.onCreateNode = (
{ node, actions: { createNodeField }, getNode },
themeOptions
) => {
if (node.internal.type !== `Mdx`) {
return;
}

const { basePath } = withDefault(themeOptions);

let value = createFilePath({ node, getNode });
if (value === "index") value = "";

createNodeField({
name: `slug`,
node,
value: normalizeBasePath(basePath, value),
});

createNodeField({
name: `id`,
node,
value: node.id,
});
};

/**
[
{
"node": {
"label": "Home",
"link": "/",
"items": null,
"id": "a2913be3-af3c-5fc9-967e-a058e86b20a9"
}
},
{
"node": {
"label": "With dropdown",
"link": null,
"items": [
{ "label": "My Example", "link": "/my-example" },
{ "label": "Teste 2", "link": "/teste-2" }
],
"id": "c7d9606c-4bda-5097-a0df-53108e9f4efd"
}
}
]
*/

// Ler todo o array e salvar em uma objeto chave/valor
/**
* {
* '/': {
* prev: null,
* next: {
* label: 'My example',
* link: '/my-example'
* }
* },
* '/my-example': {
* prev: {
* label: 'Home',
* link: '/'
* },
* next: {
* label: 'Teste 2',
* link: '/teste-2'
* }
* },
* '/teste-2': {
* prev: {
* label: 'My example',
* link: '/my-example'
* },
* next: null
* }
* }
*/
2 changes: 2 additions & 0 deletions docs/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { wrapRootElement } from "./src/@rocketseat/gatsby-theme-docs/gatsby/wrapRootElement";
export { wrapPageElement } from "./src/@rocketseat/gatsby-theme-docs/gatsby/wrapPageElement";
Loading