Skip to content

Commit f95d515

Browse files
author
Peter Bengtsson
authored
Spot redirect orphans better (github#34800)
1 parent 5a7f225 commit f95d515

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

content/actions/migrating-to-github-actions/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ versions:
88
ghae: '*'
99
ghec: '*'
1010
redirect_from:
11-
- /actions/migrating-to-github-actions
1211
- /articles/migrating-github-actions-from-hcl-syntax-to-yaml-syntax
1312
children:
1413
- /automating-migration-with-github-actions-importer
@@ -18,4 +17,3 @@ children:
1817
- /migrating-from-jenkins-to-github-actions
1918
- /migrating-from-travis-ci-to-github-actions
2019
---
21-

content/admin/identity-and-access-management/using-saml-for-enterprise-iam/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ versions:
99
redirect_from:
1010
- /github/setting-up-and-managing-your-enterprise/configuring-identity-and-access-management-for-your-enterprise-account
1111
- /admin/authentication/managing-identity-and-access-for-your-enterprise
12-
- /admin/identity-and-access-management/managing-iam-for-your-enterprise
1312
- /admin/authentication/configuring-authentication-and-provisioning-with-your-identity-provider
1413
- /enterprise/admin/articles/configuring-saml-authentication
1514
- /enterprise/admin/articles/about-saml-authentication

content/authentication/authenticating-with-saml-single-sign-on/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ redirect_from:
55
- /articles/authenticating-to-a-github-organization-with-saml-single-sign-on
66
- /articles/authenticating-with-saml-single-sign-on
77
- /github/authenticating-to-github/authenticating-with-saml-single-sign-on
8-
- /authentication/authenticating-with-saml-single-sign-on
98
versions:
109
ghae: '*'
1110
ghec: '*'
@@ -18,4 +17,3 @@ children:
1817
- /viewing-and-managing-your-active-saml-sessions
1918
shortTitle: Authenticate with SAML
2019
---
21-

lib/permalink.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ class Permalink {
5858
}
5959

6060
static relativePathToSuffix(relativePath) {
61-
return '/' + relativePath.replace('index.md', '').replace('.md', '')
61+
if (relativePath === 'index.md') return '/'
62+
// When you turn `foo/bar.md`, which is a file path, into a URL pathname,
63+
// you just need to chop off the `.md` suffix.
64+
// For `foo/parent/index.md` you can't just chop off the `index.md`
65+
// because it would leave a trailing `/`.
66+
return `/${relativePath.replace(indexmdSuffixRegex, '').replace(mdSuffixRegex, '')}`
6267
}
6368
}
6469

70+
const indexmdSuffixRegex = new RegExp(`${path.sep}index\\.md$`)
71+
const mdSuffixRegex = /\.md$/
72+
6573
export default Permalink

tests/content/redirect-orphans.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import path from 'path'
2-
import { jest, beforeAll } from '@jest/globals'
2+
3+
import { jest } from '@jest/globals'
34

45
import { loadPages } from '../../lib/page-data.js'
56
import Permalink from '../../lib/permalink.js'
67

78
describe('redirect orphans', () => {
8-
let pageList
9-
109
// Because calling `loadPages` will trigger a warmup, this can potentially
1110
// be very slow in CI. So we need a timeout.
1211
jest.setTimeout(60 * 1000)
1312

14-
beforeAll(async () => {
13+
test('no page is a redirect in another file', async () => {
1514
// Only doing English because they're the only files we do PRs for.
16-
pageList = (await loadPages()).filter((page) => page.languageCode === 'en')
17-
})
15+
const pageList = await loadPages(undefined, ['en'])
1816

19-
test('no page is a redirect in another file', () => {
2017
const redirectFroms = new Map()
2118
for (const page of pageList) {
2219
for (const redirectFrom of page.redirect_from || []) {

0 commit comments

Comments
 (0)