Skip to content

Commit

Permalink
chore: merge develop in
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlight-komorebi committed Dec 14, 2021
2 parents f13b514 + 6d54b3c commit 666cded
Show file tree
Hide file tree
Showing 870 changed files with 17,404 additions and 10,834 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
*.js @newrelic/developer-enablement

yarn.lock @newrelic/developer-enablement

# Whats new files (pings individual project marketing managers)

/src/content/whats-new/ @ishanmkh @jkinmonth @alexiskjones @molson10 @daynaslord
29 changes: 20 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,32 +151,43 @@ To submit a [Draft PR](https://github.blog/2019-02-14-introducing-draft-pull-req
### Using Conventional Commits

Please help the maintainers by leveraging the following [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/)
standards in your pull request title and commit messages.
standards in your commit messages. You don't need to apply this format to the pull request title–just to commits.

As a reminder, here's the format for a single-line commit, but you are welcome to add the optional body and footer messages.

```
<type>(optional scope): <description>
```

When choosing a type, you can pick from any of the standard types (feat, fix, style, test, or chore) or you can add your own.
**Note**: There is a `documentation` type, but please refrain from using it for general documentation changes since it is intended for changes to the repository's documentation (such as `README.md` and `CONTRIBUTING.md`)

As far as scope, we recommend that you include this because it helps us identify relevant commits. For the docs project, the scope might refer to the part of the docs you are editing (for example, APM or errors inbox). If you are suggesting a code change to the docs site, insert the section of the codebase you worked on.

Here are some examples:

#### Use `chore`

- for minor changes / additions / corrections to content.
- for minor changes / additions / corrections to images.
- for minor non-functional changes / additions to github actions, github templates, package or config updates, etc
Chores are best for changes that users don't see directly, such as improving unit tests or reducing technical debt. You might use them for minor non-functional changes/additions to github actions, github templates, package or config updates, etc.

```bash
git commit -m "chore: adjusting config and content"
git commit -m "chore(translation): extend translation unit test coverage"
```

#### Use `fix`

- for minor functional corrections to code.
Fix is used for minor functional corrections to code.

```bash
git commit -m "fix: typo and prop error in the code of conduct"
git commit -m "fix(Log management): repair broken link in introduction"
```

#### Use `feat`

- for major functional changes or additions to code.
Feat is for major functional changes or additions to code.

```bash
git commit -m "feat(media): creating a video landing page"
git commit -m "feat(errors inbox): add new documents"
```

### Deploy previews with Gatsby Cloud
Expand Down
5 changes: 3 additions & 2 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
oneTrustID: 'e66f9ef1-3a12-4043-b7c0-1a2ea66f6d41',
forceTrailingSlashes: true,
layout: {
contentPadding: '2rem',
contentPadding: '1.5rem',
maxWidth: '1600px',
component: require.resolve('./src/layouts'),
mobileBreakpoint: '760px',
Expand All @@ -67,6 +67,7 @@ module.exports = {
'xml-doc',
'c',
'go',
'handlebars',
'java',
'php',
'phpdoc',
Expand Down Expand Up @@ -189,7 +190,7 @@ module.exports = {
segmentWriteKey: 'AEfP8c1VSuFxhMdk3jYFQrYQV9sHbUXx',
trackPageViews: true,
pageView: {
name: 'pageView',
eventName: 'pageView',
category: 'DocPageView',
getProperties: ({ location, env }) => ({
path: location.pathname,
Expand Down
9 changes: 7 additions & 2 deletions gatsby/on-route-update.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const onRouteUpdate = ({ location, prevLocation }) => {
if (
window.newrelic &&
window.Tessen &&
location.hash &&
location.pathname !== prevLocation?.pathname
) {
window.newrelic.addPageAction('hash_request', { hash: location.hash });
window.Tessen.track({
eventName: 'hashRequest',
category: 'AnchorClick',
pathname: location.pathname,
hash: location.hash,
});
}
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"common-tags": "^1.8.0",
"date-fns": "^2.17.0",
"front-matter": "^4.0.2",
"gatsby": "^3.8.1",
"gatsby": "^3.14.0",
"gatsby-image": "^3.8.0",
"gatsby-plugin-gatsby-cloud": "^2.8.1",
"gatsby-plugin-json-output": "^1.2.0",
Expand All @@ -24,7 +24,7 @@
"gatsby-plugin-meta-redirect": "^1.1.1",
"gatsby-plugin-offline": "^4.8.0",
"gatsby-plugin-react-helmet": "^4.8.0",
"gatsby-plugin-sharp": "^3.14.1",
"gatsby-plugin-sharp": "^3.14.3",
"gatsby-remark-autolink-headers": "^4.5.0",
"gatsby-remark-copy-linked-files": "^4.5.0",
"gatsby-remark-images": "^5.5.0",
Expand Down Expand Up @@ -153,6 +153,7 @@
"add-files-to-translate": "node scripts/actions/add-files-to-translation-queue.js",
"check-for-outdated-translations": "node scripts/actions/check-for-outdated-translations.js",
"verify-mdx": "node scripts/verify_mdx.js",
"add-remove-redirects": "node scripts/utils/docs-content-tools/add-remove-redirects.js",
"db:start": "docker-compose --file scripts/actions/translation_workflow/testing/docker-compose.yml up --build",
"db:clean": "./scripts/actions/translation_workflow/testing/cleanup.sh"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/gatsby-plugin-generate-doc-json/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ exports.onPostBuild = async ({ graphql, store }) => {
const imageHashMap = allImageSharp.nodes.reduce(
(acc, { original, parent }) => ({
...acc,
[parent.relativePath]: original.src,
[parent.relativePath]: original?.src || null,
}),
{}
);
Expand Down
72 changes: 72 additions & 0 deletions scripts/utils/docs-content-tools/add-remove-redirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const {
getFilePaths,
getUserInputs,
separateData,
joinData,
addRedirect,
removeRedirect,
} = require('./handlers');
const fs = require('fs');

/**
* Process the results from the add/remove redirects and prints them
* @param {Object} results - Object containing either added/skipped/removed redirects
*/
const processResults = (results) => {
const addedRedirects = results.filter((file) => file.added);
const skippedRedirects = results.filter((file) => file.skipped);
const removedRedirects = results.filter((file) => file.removed);

if (addedRedirects.length) {
console.log('(✔️) Added Redirects to the following paths:');
addedRedirects.forEach((filepath) => console.log(` - ${filepath.added}`));
}

if (removedRedirects.length) {
console.log('(✔️) Removed Redirects from the following paths:');
removedRedirects.forEach((filepath) =>
console.log(` - ${filepath.removed}`)
);
}

if (skippedRedirects.length) {
console.log(
'(✔️) The following files either contain no redirects or already contain the slug:'
);
skippedRedirects.forEach((filepath) =>
console.log(` - ${filepath.skipped}`)
);
}
};

const main = async () => {
const { action, directory } = getUserInputs();
const filePaths = getFilePaths(directory);

if (!filePaths.length) {
console.warn(`<!> No .mdx files found in the directory. Please check: ${directory}`);
return;
}

const separatedData = filePaths.map(separateData);

const editedData = separatedData.map((data) => {
if (action === 'add') {
return addRedirect(data);
}
return removeRedirect(data);
});

const joinedData = editedData.map(joinData);

joinedData.forEach(({ data, path }) => {
try {
fs.writeFileSync(path, String(data));
} catch (err) {
console.error(err);
}
});
processResults(editedData);
};

main();
170 changes: 170 additions & 0 deletions scripts/utils/docs-content-tools/handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
const glob = require('glob');
const frontmatterGH = require('@github-docs/frontmatter');
const fs = require('fs');

/**
* Adds slashes to beginning and end of directory if missing
* @param {String} directory - The directory to add slashes to
* @returns {String} The directory with slashes added if necessary
*/
const formatDirectory = (directory) => {
if (!directory.startsWith('/')) {
return `/${directory}`;
} else if (!directory.endsWith('/')) {
return directory.concat('/');
}

return directory;
};

/**
* Gets slug from path, relative to contents folder
* @param {String} filepath - The full filepath of the file
* @returns {String} The slug of the filepath
*/
const getSlugFromPath = (filepath) => {
const slug = filepath.match(/content(.*?).mdx/)[1];
if (!slug) {
console.error(
`<!> Could not find slug from path: ${filepath}, please check filepath`
);
process.exit(1);
}
return slug;
};

/**
* Reads a file and separates the content and frontmatter data
* @param {String} path - The full filepath of the file
* @returns {Object} Original path, slug from path, content, frontmatter data
*/
const separateData = (path) => {
const file = fs.readFileSync(path, 'utf8');
const slug = getSlugFromPath(path);
const separateData = frontmatterGH(file);
const { data: frontmatterData, content } = separateData;
if (!frontmatterData.redirects) {
frontmatterData.redirects = [];
}
return { path, content, frontmatterData, slug };
};

/**
* Joins the content and frontmatter data
* @param {Object} data - content, frontmatterData, path
* @returns {Object} Combined data and path
*/
const joinData = ({ content, frontmatterData, path }) => {
const data = frontmatterGH.stringify(content, frontmatterData, {
lineWidth: -1,
});

return { path, data };
};

/**
* Adds a redirect if the slug is not already in the redirects array
* @param {Object} data - slug, frontmatterData, rest
* @returns {Object} Edited frontmatterData, whether the redirect was added or skipped
*/
const addRedirect = ({ frontmatterData, slug, ...rest }) => {
if (frontmatterData.redirects.includes(slug)) {
return { frontmatterData, ...rest, skipped: slug };
}
return {
frontmatterData: {
...frontmatterData,
redirects: [...frontmatterData.redirects, slug],
},
...rest,
added: slug,
};
};

/**
* Removes a redirect if the slug is in the redirects array
* @param {Object} data - slug, frontmatterData, rest
* @returns {Object} Edited frontmatterData, whether the redirect was removed or skipped
*/
const removeRedirect = ({ frontmatterData, slug, ...rest }) => {
if (frontmatterData.redirects.includes(slug)) {
frontmatterData.redirects = frontmatterData.redirects.filter(
(path) => path !== slug
);
if (frontmatterData.redirects.length === 0) {
delete frontmatterData.redirects;
}
return {
frontmatterData,
...rest,
removed: slug,
};
}
return { frontmatterData, ...rest, skipped: slug };
};

/**
* Globs an array of all mdx files in a directory + sub-directories
* @param {String} directory - The parent directory to search
* @returns {String[]} All mdx files in the directory and sub-directories
*/
const getFilePaths = (directory) => {
const subDir = directory.length ? directory : '/docs/';
return glob.sync(`${__dirname}/../../../src/content${subDir}**/*.mdx`);
};

/**
* Retrieves the user inputs from command line
* @returns {Object} The directory and action specified by the user
*/
const getUserInputs = () => {
const userInputs = process.argv.slice(2);
const actionInput = userInputs.find((input) =>
['--add', '--remove'].includes(input)
);

const printExample = () =>
console.warn(
'Example: yarn add-remove-redirects --add src/content/docs/apm'
);

if (!actionInput) {
console.warn(
'<!> No action specified, please append `--add` or `--remove` to the command'
);
printExample();
process.exit(0);
}

const action = actionInput.replace('--', '');

const directoryInput = userInputs.find((input) => input !== actionInput);

if (!directoryInput) {
console.warn(
'<!> No directory specified, please include the directory you want to apply changes to'
);
printExample();
process.exit(0);
}

const formattedDirectory = formatDirectory(directoryInput);
if (!fs.existsSync(`src/content/${formattedDirectory}`)) {
console.warn(
'<!> The directory does not exist, please check the your path. Remember that you should not include the `src/content` portion of the path.'
);
printExample();
process.exit(0);
}

return { action, directory: formattedDirectory };
};

module.exports = {
getFilePaths,
getUserInputs,
separateData,
joinData,
addRedirect,
removeRedirect,
};

0 comments on commit 666cded

Please sign in to comment.