-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91b04fd
commit dc98328
Showing
13 changed files
with
164 additions
and
116 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
'use server'; | ||
|
||
import { cookies, draftMode, headers } from 'next/headers'; | ||
import { redirect } from 'next/navigation'; | ||
import { COOKIE_NAME } from '../handlers/previewRouteHandler'; | ||
|
||
export async function disableDraftMode() { | ||
const currentUrl = headers().get('x-headstartwp-current-url') ?? '/'; | ||
draftMode().disable(); | ||
cookies().delete(COOKIE_NAME); | ||
redirect(currentUrl); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { BlocksRenderer } from '@headstartwp/core/react'; | ||
import { getHeadstartWPConfig, setHeadstartWPConfig } from '@headstartwp/core'; | ||
import { LinkBlock } from '../LinkBlock'; | ||
|
||
describe('LinkBlock', () => { | ||
it('shound replace internal links with next/link', () => { | ||
setHeadstartWPConfig({ | ||
sourceUrl: 'http://wpadmin.com', | ||
hostUrl: 'http://domain.com', | ||
}); | ||
|
||
const { container } = render( | ||
<BlocksRenderer | ||
html="<div class='content'><a href='http://wpadmin.com/post-name'>This is an internal link</a>></div>" | ||
settings={getHeadstartWPConfig()} | ||
> | ||
<LinkBlock /> | ||
</BlocksRenderer>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/next/src/rsc/blocks/__tests__/__snapshots__/LinkBlock.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`LinkBlock shound replace internal links with next/link 1`] = ` | ||
<div> | ||
<div | ||
class="content" | ||
> | ||
<a | ||
class="" | ||
href="/post-name" | ||
> | ||
This is an internal link | ||
</a> | ||
> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
SettingsContextProps, | ||
SettingsProvider, | ||
ThemeSettingsProvider, | ||
} from '@headstartwp/core/react'; | ||
import React, { FC, ReactNode } from 'react'; | ||
import { AppEntity } from '@headstartwp/core'; | ||
|
||
type HeadstartWPAppProps = { | ||
/** | ||
* Supported settings by the framework. Such as custom image component, custom link component etc. | ||
* | ||
* @see {@link SettingsContextProps} | ||
*/ | ||
settings: SettingsContextProps; | ||
|
||
/** | ||
* Theme settings from the `theme.json`. | ||
* | ||
* Passing this will expose theme json through `useThemeSettings` hook. | ||
*/ | ||
themeJSON?: AppEntity['theme.json']; | ||
|
||
children?: ReactNode; | ||
}; | ||
|
||
export const HeadstartWPApp: FC<HeadstartWPAppProps> = ({ settings, children, themeJSON = {} }) => { | ||
return ( | ||
<SettingsProvider settings={settings}> | ||
<ThemeSettingsProvider data={themeJSON}>{children}</ThemeSettingsProvider> | ||
</SettingsProvider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { SettingsProvider } from '@headstartwp/core/react'; | ||
import { Link } from '../Link'; | ||
|
||
describe('Link', () => { | ||
it('shound replace internal links with next/link', () => { | ||
const { container } = render( | ||
<SettingsProvider | ||
settings={{ | ||
sourceUrl: 'http://wpadmin.com', | ||
hostUrl: 'http://domain.com', | ||
}} | ||
> | ||
<Link href="http://wpadmin.com/post-name" /> | ||
</SettingsProvider>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/next/src/rsc/components/__tests__/__snapshots__/Link.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Link shound replace internal links with next/link 1`] = ` | ||
<div> | ||
<a | ||
href="/post-name" | ||
/> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.