Skip to content

Commit 919c0bc

Browse files
committed
fix: use relative filepath for Algolia slugs
1 parent bbfb167 commit 919c0bc

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/contexts/i18n-provider.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export const useI18n = () => {
1111
export default function I18nProvider({ children }) {
1212
const { locale } = useLocale();
1313

14-
console.log('i18n locale', locale);
15-
1614
const i18nContextValue = React.useMemo(() => {
1715
return {
1816
t: (key) => {

src/utils/algolia.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ const {
1111
DEFAULT_LOCALE,
1212
} = require('./utils.node');
1313

14-
const processMdxEntry = ({ children: [entry] }, kind = 'docs') => {
14+
const processMdxEntry = (
15+
{ children: [entry], relativeDirectory },
16+
kind = 'docs',
17+
) => {
1518
const {
16-
fileAbsolutePath,
1719
mdxAST,
1820
objectID,
1921
frontmatter: { title, redirect, slug: customSlug },
@@ -26,28 +28,24 @@ const processMdxEntry = ({ children: [entry] }, kind = 'docs') => {
2628
* avoid indexing this section for a while to avoid
2729
* search user's confusion
2830
*/
29-
if (/cloud rest api/i.test(fileAbsolutePath)) {
31+
if (/cloud rest api/i.test(relativeDirectory)) {
3032
// eslint-disable-next-line no-console
31-
console.log('exluded from algolia indecies pages:', fileAbsolutePath);
33+
console.log('exluded from algolia indecies pages:', relativeDirectory);
3234
return [];
3335
}
3436

3537
// @TODO: remove to enable sending spanish content to Algolia
3638
if (I18N_CONFIG.hideEsFromAlgoliaSearch) {
37-
if (/\/es\//i.test(fileAbsolutePath)) {
39+
if (/\/es\//i.test(relativeDirectory)) {
3840
// eslint-disable-next-line no-console
39-
console.log('exluded ES page from algolia indecies:', fileAbsolutePath);
41+
console.log('exluded ES page from algolia indecies:', relativeDirectory);
4042
return [];
4143
}
4244
}
4345

44-
const strippedDirectory = stripDirectoryPath(fileAbsolutePath, kind);
46+
const strippedDirectory = stripDirectoryPath(relativeDirectory, kind);
4547
// cut the last piece (the actual name of a file) to match the generation in node
46-
const cutStrippedDirectory = strippedDirectory
47-
.split('/')
48-
.slice(0, -1)
49-
.join('/');
50-
const path = `/${cutStrippedDirectory}/${title.replace(/\//g, '-')}`;
48+
const path = `/${strippedDirectory}/${title.replace(/\//g, '-')}`;
5149

5250
const pageLocale =
5351
SUPPORTED_LOCALES.find((locale) => path.startsWith(`/${locale}/`)) ||
@@ -56,7 +54,7 @@ const processMdxEntry = ({ children: [entry] }, kind = 'docs') => {
5654
const slug =
5755
pageLocale === DEFAULT_LOCALE
5856
? getSlug(path)
59-
: getTranslatedSlug(cutStrippedDirectory, title, pageLocale, 'guides');
57+
: getTranslatedSlug(strippedDirectory, title, pageLocale, 'guides');
6058

6159
const pageSlug = customSlug || slug;
6260
const chunks = chunk(mdxAstToPlainText(mdxAST), 300);
@@ -67,7 +65,7 @@ const processMdxEntry = ({ children: [entry] }, kind = 'docs') => {
6765
cache[pointer] = {
6866
title,
6967
objectID: `${objectID}-${pointer}`,
70-
slug: pageSlug,
68+
slug: pageSlug.startsWith('/') ? pageSlug : `/${pageSlug}`,
7169
content: chunks[pointer],
7270
};
7371
}
@@ -88,9 +86,10 @@ const flatten = (arr, kind = 'docs') => {
8886
// main query
8987
const docPagesQuery = `{
9088
docPages: allFile(
91-
filter: { absolutePath: { regex: "/\/docs\//" }, ext:{in: [".md"]} }
89+
filter: { relativeDirectory: { regex: "/\/docs\//" }, ext:{in: [".md"]} }
9290
) {
9391
nodes {
92+
relativeDirectory
9493
children {
9594
... on Mdx {
9695
objectID: id
@@ -100,7 +99,6 @@ const docPagesQuery = `{
10099
slug
101100
}
102101
mdxAST
103-
fileAbsolutePath
104102
}
105103
}
106104
}
@@ -110,9 +108,10 @@ const docPagesQuery = `{
110108
// translated guides
111109
const guidesPagesQuery = `{
112110
guidesPages: allFile(
113-
filter: { absolutePath: { regex: "/\/translated-guides\//" }, ext:{in: [".md"]} }
111+
filter: { relativeDirectory: { regex: "/\/translated-guides\//" }, ext:{in: [".md"]} }
114112
) {
115113
nodes {
114+
relativeDirectory
116115
children {
117116
... on Mdx {
118117
objectID: id
@@ -122,7 +121,6 @@ const guidesPagesQuery = `{
122121
slug
123122
}
124123
mdxAST
125-
fileAbsolutePath
126124
}
127125
}
128126
}
@@ -136,7 +134,7 @@ const settings = {
136134
distinct: true,
137135
};
138136

139-
const indexName = process.env.GATSBY_ALGOLIA_INDEX_NAME || 'dev_k6_docs';
137+
const indexName = process.env.GATSBY_ALGOLIA_INDEX_NAME || 'test-setup';
140138

141139
const queries = [
142140
{

0 commit comments

Comments
 (0)