Skip to content

Commit

Permalink
Release docs (#658)
Browse files Browse the repository at this point in the history
<!--
Filling out this template is required. Any PR that does not include
enough information to be reviewed may be closed at a maintainers'
discretion. All new code requires documentation and tests to ensure
against regressions.
-->

### Description of the Change
<!--
We must be able to understand the design of your change from this
description. The maintainer reviewing this PR may not have worked with
this code recently, so please provide as much detail as possible.

Where possible, please also include:
- verification steps to ensure your change has the desired effects and
has not introduced any regressions
- any benefits that will be realized
- any alternative implementations or possible drawbacks that you
considered
- screenshots or screencasts
-->

<!-- Enter any applicable Issue number(s) here that will be
closed/resolved by this PR. -->
Closes #

### How to test the Change
<!-- Please provide steps on how to test or validate that the change in
this PR works as described. -->

### Changelog Entry
<!--
Please include a summary for this PR, noting whether this is something
being Added / Changed / Deprecated / Removed / Fixed / or Security
related. You can replace the sample entries after this comment block
with the single changelog entry line for this PR. -->
> Added - New feature
> Changed - Existing functionality
> Deprecated - Soon-to-be removed feature
> Removed - Feature
> Fixed - Bug fix
> Security - Vulnerability


### Credits
<!-- Please list any and all contributors on this PR so that they can be
added to this projects CREDITS.md file. -->
Props @username, @username2, ...


### Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you are unsure about any of these, please ask for
clarification. We are here to help! -->
- [ ] I agree to follow this project's [**Code of
Conduct**](https://github.com/10up/.github/blob/trunk/CODE_OF_CONDUCT.md).
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my change.
- [ ] All new and existing tests pass.
  • Loading branch information
nicholasio authored Dec 1, 2023
2 parents 8ab111d + ddd728d commit be6cbae
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 19 deletions.
5 changes: 0 additions & 5 deletions docs/documentation/08-Guides/complex-urls-structure.md

This file was deleted.

13 changes: 13 additions & 0 deletions docs/documentation/08-Guides/linaria.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Linaria (CSS-in-JS)

HeadstartWP offers a straightforward integration with [Linaria](https://github.com/callstack/linaria), a zero-runtime CSS-in-JS solution. To use it, simply install the following linaria packages.

```
npm install --save-dev @linaria/babel-preset @linaria/core @linaria/react @linaria/shaker @linaria/webpack-loader
```

The [withHeadstartWPConfig](/docs/api/namespaces/headstartwp_next.config/#withheadstartwpconfig) function will detect the presence of the Linaria packages and will enable the build steps necessary to compile Linaria.

:::caution
If you're on a monorepo setup, these packages should be installed on the Next.js project.
:::caution
4 changes: 2 additions & 2 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ const config = {
require.resolve('@easyops-cn/docusaurus-search-local'),
{
indexDocs: true,
docsRouteBasePath: ['reference', 'docs'],
docsDir: ['default', 'docs'],
docsRouteBasePath: ['api', 'learn'],
docsDir: ['documentation', 'docs'],
hashed: true,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export class SinglePostFetchStrategy<

if (!post) {
throw new NotFoundError(
`Post was found but did not match current path: "${this.path}""`,
`Post #${result[0].id} - "${result[0].link}" was found but did not match current path: "${this.path}""`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('PostOrPostsFetchStrategy', () => {
);

await expect(() => fetchStrategy.fetcher('', params)).rejects.toThrow(
'Neither single or archive returned data: The request to /wp-json/wp/v2/posts?_embed=true&categories=distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam returned no data, Post was found but did not match current path: "/uncategorized/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam"',
'Neither single or archive returned data: The request to /wp-json/wp/v2/posts?_embed=true&categories=distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam returned no data, Post #54 - "https://js1.10up.com/2020/05/07/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam/" was found but did not match current path: "/uncategorized/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam"',
);

// now make it work by faking full path
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/react/hooks/__tests__/useFetchPost.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { renderHook, waitFor } from '@testing-library/react';
import * as React from 'react';
import { expectTypeOf } from 'expect-type';
import { SWRConfig } from 'swr';
import { DRAFT_POST_ID, VALID_AUTH_TOKEN } from '../../../../test/server';
import { PostEntity, PostParams } from '../../../data';
import { SettingsProvider } from '../../provider';
Expand All @@ -10,7 +11,11 @@ import { mockUseFetchErrorResponse } from '../mocks';

describe('useFetchPost', () => {
const wrapper = ({ children }) => {
return <SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>;
return (
<SWRConfig value={{ provider: () => new Map() }}>
<SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>
</SWRConfig>
);
};

it('throws errors if accessing data before fetch', async () => {
Expand Down Expand Up @@ -185,7 +190,15 @@ describe('useFetchPost', () => {

it('reads param from the url and sets isMainQuery flag', async () => {
const { result } = renderHook(
() => useFetchPost({}, {}, '/modi-qui-dignissimos-sed-assumenda-sint-iusto'),
() =>
useFetchPost(
{
fullPath:
'https://js1.10up.com/2020/05/07/modi-qui-dignissimos-sed-assumenda-sint-iusto/',
},
{},
'/modi-qui-dignissimos-sed-assumenda-sint-iusto/',
),
{
wrapper,
},
Expand All @@ -200,7 +213,7 @@ describe('useFetchPost', () => {
});

const { result: secondResult } = renderHook(
() => useFetchPost({ slug: 'modi-qui-dignissimos-sed-assumenda-sint-iusto' }),
() => useFetchPost({ slug: 'modi-qui-dignissimos-sed-assumenda-sint-iusto' }, {}),
{
wrapper,
},
Expand Down
17 changes: 13 additions & 4 deletions packages/core/src/react/hooks/__tests__/useFetchPostOrPosts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { renderHook, waitFor } from '@testing-library/react';
import { SWRConfig } from 'swr';
import { SettingsProvider } from '../../provider';
import { setHeadstartWPConfig } from '../../../utils';
import { useFetchPostOrPosts } from '../useFetchPostOrPosts';
Expand All @@ -11,6 +12,14 @@ import { mockUseFetchErrorResponse } from '../mocks';

describe('useFetchPostOrPosts', () => {
const wrapper = ({ children }) => {
return (
<SWRConfig value={{ provider: () => new Map() }}>
<SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>
</SWRConfig>
);
};

const wrapperWithCache = ({ children }) => {
return <SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>;
};

Expand Down Expand Up @@ -120,7 +129,7 @@ describe('useFetchPostOrPosts', () => {
'/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam',
),
{
wrapper,
wrapper: wrapperWithCache,
},
);

Expand All @@ -138,7 +147,7 @@ describe('useFetchPostOrPosts', () => {
'/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam',
),
{
wrapper,
wrapper: wrapperWithCache,
},
);

Expand All @@ -161,7 +170,7 @@ describe('useFetchPostOrPosts', () => {
};

const { result } = renderHook(() => useFetchPostOrPosts(p, undefined, '/uncategorized'), {
wrapper,
wrapper: wrapperWithCache,
});

await waitFor(() => {
Expand All @@ -171,7 +180,7 @@ describe('useFetchPostOrPosts', () => {
const { result: result2 } = renderHook(
() => useFetchPosts(p.archive, undefined, '/uncategorized'),
{
wrapper,
wrapper: wrapperWithCache,
},
);

Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/react/hooks/__tests__/useFetchPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import * as React from 'react';

import { SWRConfig } from 'swr';
import { PostEntity, PostsArchiveParams } from '../../../data';
import { SettingsProvider } from '../../provider';
import { useFetchPosts } from '../useFetchPosts';
Expand All @@ -11,7 +12,11 @@ import { mockUseFetchErrorResponse } from '../mocks';

describe('useFetchPosts', () => {
const wrapper = ({ children }) => {
return <SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>;
return (
<SWRConfig value={{ provider: () => new Map() }}>
<SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>
</SWRConfig>
);
};

beforeEach(() => {
Expand Down Expand Up @@ -338,7 +343,7 @@ describe('useFetchPosts', () => {
() =>
useFetchPosts(
{
randomArgument: 10, // bypass swr cache
// randomArgument: 10, // bypass swr cache
category: 'uncategorized',
per_page: 1,
},
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/react/hooks/__tests__/useFetchSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import * as React from 'react';

import { SWRConfig } from 'swr';
import { PostEntity, PostsArchiveParams } from '../../../data';
import { SettingsProvider } from '../../provider';
import { useFetchSearch } from '../useFetchSearch';
Expand All @@ -11,7 +12,11 @@ import { mockUseFetchErrorResponse } from '../mocks';

describe('useFetchSearch', () => {
const wrapper = ({ children }) => {
return <SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>;
return (
<SWRConfig value={{ provider: () => new Map() }}>
<SettingsProvider settings={{ sourceUrl: '' }}>{children}</SettingsProvider>
</SWRConfig>
);
};

setHeadlessConfig({
Expand Down

0 comments on commit be6cbae

Please sign in to comment.