Skip to content

Commit 23b82a1

Browse files
tabathadelaneclarkmcadoosunnyzanchi
authored
Move images to static folder (newrelic#18203)
* feat: turn off mdx image import check * chore: add src/images to protected files actions * fix: link to image style guide page in protected file check * fix: fix rss feed image src * chore: add temp scripts * add contributor code guide for image updates * fix: cleanup images * feat: move whats-new images to static folder * chore: remove old images * feat: move images from src to static --------- Co-authored-by: Clark McAdoo <[email protected]> Co-authored-by: Sunny Zanchi <[email protected]>
1 parent 87b5cf0 commit 23b82a1

File tree

13,908 files changed

+320870
-273849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

13,908 files changed

+320870
-273849
lines changed

.github/workflows/protected-file-comment.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ jobs:
3131
pattern: .*src/content/docs/apm/agents/ruby-agent/configuration/ruby-agent-configuration.mdx
3232
trustedAuthors: newrelic-ruby-agent-bot,kaylareopelle,hannahramadan,tannalynn,fallwith
3333

34+
- name: Prevent images added to src directory
35+
id: images
36+
uses: xalvarez/[email protected]
37+
with:
38+
githubToken: ${{ secrets.GITHUB_TOKEN }}
39+
pattern: .*src\/images\/*
40+
3441
- name: Comment if JSON file is modified
3542
if: ${{ failure() && steps.attribute-dictionary.outcome == 'failure' }}
3643
uses: thollander/actions-comment-pull-request@v2
3744
with:
3845
message: |
3946
> [!WARNING]
40-
> `attribute-dictionary.json` is an autogenerated file.
47+
> **`attribute-dictionary.json` is an autogenerated file.**
4148
>
4249
> Changes to attribute dictionary should be made through the `attribute-dictionary` repo in GHE.
4350
@@ -47,6 +54,16 @@ jobs:
4754
with:
4855
message: |
4956
> [!WARNING]
50-
> `ruby-agent-configuration.mdx` is an autogenerated file.
57+
> **`ruby-agent-configuration.mdx` is an autogenerated file.**
5158
>
5259
> To change the Ruby agent configuration file, please submit an issue or open a PR in the [`newrelic/newrelic-ruby-agent`](https://github.com/newrelic/newrelic-ruby-agent) repo.
60+
61+
- name: Comment if images added to src directory
62+
if: ${{ failure() && steps.images.outcome == 'failure' }}
63+
uses: thollander/actions-comment-pull-request@v2
64+
with:
65+
message: |
66+
> [!WARNING]
67+
> **An image has been added to `src/images/`.**
68+
>
69+
> Image files must be in `static/images/`. [Guide to using images in docs-website](https://github.com/newrelic/docs-website/blob/master/src/content/docs/style-guide/images/embed-images.mdx)

gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = {
7979
background_color: '#663399',
8080
theme_color: '#663399',
8181
display: 'minimal-ui',
82-
icon: 'src/images/favicon.png', // This path is relative to the root of the site.
82+
icon: 'static/images/favicon.png', // This path is relative to the root of the site.
8383
},
8484
},
8585
{

gatsby-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exports.onCreateWebpackConfig = ({ actions }) => {
3131
zlib: false,
3232
},
3333
alias: {
34-
images: path.resolve(__dirname, 'src/images/'),
34+
images: path.resolve(__dirname, 'static/images/'),
3535
},
3636
},
3737
});

plugins/utils/handlers.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const all = require('mdast-util-to-hast/lib/all');
2-
const one = require('mdast-util-to-hast/lib/one');
32
const { findAttribute } = require('../../codemods/utils/mdxast');
43
const toString = require('mdast-util-to-string');
54
const u = require('unist-builder');
6-
const { compileStyleObject } = require('../../rehype-plugins/utils/styles');
7-
const { set, get } = require('lodash');
5+
const path = require('path');
6+
const { get } = require('lodash');
87

98
const stripNulls = (obj) =>
109
Object.fromEntries(Object.entries(obj).filter(([, value]) => value != null));
@@ -16,8 +15,6 @@ const getAllAttributes = (node) =>
1615
}, {})
1716
: {};
1817

19-
const getSrcUrl = (url) => url.replace('images/', '');
20-
2118
const isBlockImage = (parent, node) => {
2219
const isBlock = [];
2320
const className = get(node, 'data.className', null);
@@ -82,13 +79,8 @@ const isBlockImage = (parent, node) => {
8279
};
8380

8481
module.exports = {
85-
image: (h, node, parent, imageHashMap) => {
86-
const domain = 'https://docs.newrelic.com';
87-
const srcUrl = getSrcUrl(node.url);
88-
89-
const src = imageHashMap[srcUrl]
90-
? new URL(imageHashMap[srcUrl], domain).href
91-
: node.url;
82+
image: (h, node, parent) => {
83+
const src = path.join('https://docs.newrelic.com', node.url);
9284

9385
const applyBlockImageAttributes = isBlockImage(parent, node);
9486

scripts/moveWnImages.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const fs = require('fs');
2+
const glob = require('glob');
3+
4+
const wnImages = glob.sync('src/content/whats-new/**/*.*', {
5+
ignore: ['**/.gitkeep', '**/*.md'],
6+
});
7+
const wnImageDirs = glob.sync('src/content/whats-new/**/images', {});
8+
9+
// images not in expected image folders:
10+
// 'src/components/backend.webp',
11+
// 'src/components/curlyAndDots.webp',
12+
// 'src/components/curlyAndDotsDM.webp',
13+
// 'src/components/devops.webp',
14+
// 'src/components/frontend.webp',
15+
16+
// these i think can be remove ^
17+
18+
// 'src/content/docs/apm/agents/net-agent/configuration/images/dotnetlogo.webp',
19+
// 'src/content/docs/new-relic-solutions/transition-user-menu.webp'
20+
21+
// these just seem incorrect ^
22+
23+
// get all images in whats new image dirs
24+
// then strip off the image file name to construct the new path
25+
26+
// src/content/whats-new/2024/02/logs-live-archives-retention.webp is not in an image folder ( but also not used?)
27+
28+
// wnImages.forEach((image) => {
29+
// const imageName = image.split('/images/');
30+
// console.log('Successfully renamed ', image, ` static/images/${imageName[1]}`);
31+
// if (imageName[1] !== undefined) {
32+
// fs.rename(image, `static/images/${imageName[1]}`, function (err) {
33+
// if (err) throw err;
34+
// });
35+
// } else {
36+
// console.log('❌', image);
37+
// }
38+
// });
39+
40+
// delete image directories and all contents (.gitignore's)
41+
// src/content/whats-new/2024/05/images/whats-new-05-08-sessiontraces.md
42+
// src/content/whats-new/2024/07/images/whats-new-07-02-apmk8s.md
43+
// there are two whats new posts in image directories we will need to pull out and rerun this
44+
45+
wnImageDirs.forEach((dir) => {
46+
fs.rmSync(dir, { recursive: true, force: true });
47+
});

scripts/updateImgSrc.js

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const glob = require('glob');
4+
const unified = require('unified');
5+
const remarkParse = require('remark-parse');
6+
const remarkMdx = require('remark-mdx');
7+
const remarkMdxjs = require('remark-mdxjs');
8+
const visit = require('unist-util-visit');
9+
const SKIP = require('unist-util-visit');
10+
const frontmatter = require('remark-frontmatter');
11+
const remarkStringify = require('remark-stringify');
12+
const fencedCodeBlock = require('./actions/utils/fencedCodeBlock');
13+
14+
/**
15+
* 1. Parse file.
16+
* 2 if import,
17+
* - add to import array as an object with attributes as keys
18+
* - delete import from file
19+
* 3. check if <img> OR component with img tag in an attribute (mdxValueExpresssion ex: techtile, collpaser)
20+
* - pull the info from it's matching import statement
21+
* to replace its 'src' attribute
22+
**/
23+
24+
let allImports = {};
25+
26+
const convertImages = () => (tree) => {
27+
visit(
28+
tree,
29+
(node) => ['import'].includes(node.type),
30+
(node, index, parent) => {
31+
const importData = node.value.split(' ');
32+
33+
const importConst = importData[1];
34+
const importPath = importData[3]
35+
.replace(/"|'/g, '')
36+
.replace('images/', '/images/');
37+
38+
allImports[importConst] = importPath;
39+
parent.children.splice(index, 1);
40+
// Skipping the removed node to avoid bugs caused by changing the tree while traversing it.
41+
return [SKIP, index];
42+
}
43+
);
44+
45+
visit(
46+
tree,
47+
(node) =>
48+
node.attributes?.some(
49+
// some components have images embeded in their attributes
50+
// ex: techtile icons, collapser titles
51+
(attr) => attr?.value?.type === 'mdxValueExpression'
52+
),
53+
(node) => {
54+
const newAttributes = node.attributes.map((attr) => {
55+
if (
56+
attr.value.type === 'mdxValueExpression' &&
57+
attr.value.value.includes('src={')
58+
) {
59+
let attribute = attr.value.value;
60+
// some collapsers have multiple images in a single title
61+
// ex: src/i18n/content/pt/docs/infrastructure/host-integrations/installation/install-infrastructure-host-integrations.mdx
62+
const oldSrcs = Array.from(attribute.matchAll(/src=\{(.*?)\}/g));
63+
oldSrcs.forEach((src) => {
64+
const oldSrc = src[1];
65+
attribute = attribute.replace(
66+
/src=\{.*?\}/,
67+
`src="${allImports[oldSrc]}"`
68+
);
69+
console.log(
70+
`🧱${node.name.toUpperCase()}: replacing ${oldSrc} with ${
71+
allImports[oldSrc]
72+
}`
73+
);
74+
return src;
75+
});
76+
attr.value.value = attribute;
77+
78+
return attr;
79+
}
80+
return attr;
81+
});
82+
node.attributes = newAttributes;
83+
}
84+
);
85+
86+
visit(
87+
tree,
88+
(node) => ['img'].includes(node.name),
89+
(node) => {
90+
const newAttributes = node.attributes.map((attr) => {
91+
if (attr.name === 'src' && attr.value.type === 'mdxValueExpression') {
92+
const attribute = attr.value.value;
93+
attr.value = allImports[attribute];
94+
console.log(
95+
`🌠IMG: replacing ${attribute} with ${allImports[attribute]}`
96+
);
97+
return attr;
98+
}
99+
return attr;
100+
});
101+
node.attributes = newAttributes;
102+
}
103+
);
104+
};
105+
106+
/**
107+
* Main function to run convertImages. Can accept command line argument
108+
* that has the path to an mdx file. Otherwise, convertImages gets ran
109+
* on every mdx file.
110+
* @returns {Array} - Resolved results from Promise
111+
*/
112+
const runConvertImages = async (paths = []) => {
113+
let filePaths = [];
114+
const processor = unified()
115+
.use(remarkParse)
116+
.use(remarkStringify, {
117+
bullet: '*',
118+
fences: true,
119+
listItemIndent: '1',
120+
})
121+
.use(remarkMdx)
122+
.use(remarkMdxjs)
123+
.use(frontmatter, ['yaml'])
124+
.use(fencedCodeBlock)
125+
.use(convertImages);
126+
127+
if (paths.length === 1) {
128+
filePaths = glob.sync(path.join(process.cwd(), paths[0]));
129+
}
130+
131+
if (paths.length === 0) {
132+
filePaths = glob.sync('src/install/**/*.mdx');
133+
}
134+
135+
const allResults = await Promise.all(
136+
filePaths.map(async (filePath) => {
137+
allImports = {};
138+
const fileData = fs.readFileSync(filePath, 'utf-8');
139+
const { contents } = await processor.process(fileData);
140+
fs.writeFileSync(filePath, contents, 'utf-8');
141+
})
142+
);
143+
144+
console.log(`Applied codemod to ${filePaths?.length} files`);
145+
return allResults;
146+
};
147+
148+
runConvertImages();

scripts/verify_mdx.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const main = async () => {
2222
filePaths = glob.sync(`${__dirname}/../${dirPath}/**/*.mdx`);
2323
}
2424

25-
verifyImages(filePaths);
2625
await verifyMDX(filePaths);
2726
};
2827

src/components/HomepageBanner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useTranslation,
99
addPageAction,
1010
} from '@newrelic/gatsby-theme-newrelic';
11-
import bannerBackground from '../images/bannerBackground.svg';
11+
import bannerBackground from 'images/bannerBackground.svg';
1212

1313
const HomepageBanner = () => {
1414
const bannerHeight = '250px';

src/components/backend.webp

-57.7 KB
Binary file not shown.

src/components/curlyAndDots.webp

-242 KB
Binary file not shown.

src/components/curlyAndDotsDM.webp

-441 KB
Binary file not shown.

src/components/devops.webp

-95.6 KB
Binary file not shown.

src/components/frontend.webp

-113 KB
Binary file not shown.

src/content/docs/accounts/accounts-billing/account-setup/choose-your-data-center.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ redirects:
1414
freshnessValidatedDate: never
1515
---
1616

17-
New Relic's global data hosting structure consists of two regions: the European Union (EU) region and the United States (US) region.
17+
New Relic's global data hosting structure consists of two regions: the European Union (EU) region and the United States (US) region.
1818

1919
## Requirements
2020

@@ -23,7 +23,7 @@ Access to the New Relic EU region requires the latest versions of our agents.
2323
* For new customers: [Install the most recent agent version](/docs/agents/manage-apm-agents/installation/install-agent).
2424
* For existing customers: [Update to the most recent agent version](/docs/agents/manage-apm-agents/installation/update-new-relic-agent).
2525

26-
Minimum <InlinePopover type="apm" /> agent version required:
26+
Minimum <InlinePopover type="apm"/> agent version required:
2727

2828
* [Go 2.0.0](/docs/release-notes/agent-release-notes/go-release-notes) or higher
2929
* [Java 4.0.0](/docs/release-notes/agent-release-notes/java-release-notes) or higher
@@ -259,4 +259,4 @@ Customer Data from existing New Relic accounts cannot be transferred or shared a
259259
Use either of these options to verify whether your account data is hosted in the EU region's data center:
260260

261261
* In APM, mouse over the application name to view the URL. If it begins with `rpm.eu.newrelic.com/`, it is an EU-based account.
262-
* Check your <InlinePopover type="licenseKey" />. If it begins with `EU`, it is an EU-based account.
262+
* Check your <InlinePopover type="licenseKey"/>. If it begins with `EU`, it is an EU-based account.

0 commit comments

Comments
 (0)