Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit ce6f329

Browse files
authored
Merge pull request #949 from WebDevStudios/hotfix/383-update-todos
Hotfix/383 update todos
2 parents 9b81a38 + 874fcef commit ce6f329

File tree

6 files changed

+116
-101
lines changed

6 files changed

+116
-101
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Link from 'next/link'
2+
3+
/**
4+
* Renders an anchor to exit Preview Mode.
5+
*
6+
* @param {object} props The component as props.
7+
* @param {object} props.preview Checks if a preview exists.
8+
* @return {Element | null} The ExitPreview component.
9+
*/
10+
export default function ExitPreview({preview}) {
11+
if (preview) {
12+
return (
13+
<p>
14+
This page is a preview.
15+
<Link href="/api/exit-preview">
16+
<a>Exit preview mode</a>
17+
</Link>
18+
</p>
19+
)
20+
}
21+
22+
return null
23+
}

components/atoms/ExitPreview/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './ExitPreview.js'

functions/isLinkActive.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,10 @@ export default function isLinkActive(asPath, path) {
1212
return false
1313
}
1414

15-
// TODO: Add functionality to check if link is in the full URL path.
16-
// e.g. /portfolio /portfolio/cambells-soup
17-
18-
return asPath === stripTrailingSlash(path)
19-
}
20-
21-
/**
22-
* Remove the last trailing slash from a URL path.
23-
*
24-
* @author WebDevStudios
25-
* @param {string} str The string to search and remove trailing slash.
26-
* @return {string} The formatted string.
27-
*/
28-
function stripTrailingSlash(str) {
29-
if (str.substr(-1) === '/' && str.length > 1) {
30-
return str.substr(0, str.length - 1)
15+
if (path.length > 1) {
16+
const checkSubStr = new RegExp(path)
17+
return checkSubStr.test(asPath)
3118
}
32-
return str
19+
20+
return path === asPath
3321
}

0 commit comments

Comments
 (0)