Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gatsby] Render just one page #5496

Closed
jquintozamora opened this issue May 21, 2018 · 13 comments
Closed

[gatsby] Render just one page #5496

jquintozamora opened this issue May 21, 2018 · 13 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@jquintozamora
Copy link

I've scenario with 5 different templates and more than 50 pages on my site.

I'd like to know if there is a cli option for gatsby which allow me to render only one given page. So If I only change the content for one page ( one url on my app ) then only that static file is generated and it doesn't update everything on my app.

Something like:
gatsby generate /mysite/mypage.html

And that specific page is updated and generated quickly, so the gatsby process does not have to process everything on my site.

Is that something I can achieve ?

Thanks!

@mquandalle
Copy link
Contributor

I guess you can implement this behavior using gatsby-node.js API and a environment variable, with something like:

exports.onCreatePage = ({ page, boundActionCreators }) => {
  const { createPage, deletePage } = boundActionCreators; // renamed to `actions` in Gatsby v2
  const singlePageMode = process.env.SINGLE_PAGE !== undefined;

  if (singlePageMode && !/404/.test(page.path) && page.path !== process.env.SINGLE_PAGE) {
    deletePage(page);
  }
};

and then, when you only want to build a single page: SINGLE_PAGE="/mypage" gatsby build

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Jun 4, 2018
@jquintozamora
Copy link
Author

Hi @mquandalle ,
Thanks for that, but I guess with that approach we still need to generate all the project and later on remove the pages we don't need. Did I understand well?
The main reason I asked for a single page approach is to save time and being able to render a preview when I change something on my CMS.

@mquandalle
Copy link
Contributor

The onCreatePage function is called at the beginning of the bundling process, when pages aren't built yet, so you'll indeed save time by using something like the above.

@gatsbot gatsbot bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Nov 30, 2018
@gatsbot
Copy link

gatsbot bot commented Dec 12, 2018

This issue is being closed due to inactivity. Is this a mistake? Please re-open this issue or create a new issue.

@gatsbot gatsbot bot closed this as completed Dec 12, 2018
@oliviertassinari
Copy link
Contributor

I have a SSR issue, I would like to debug the problem without having to rebuild the whole app between each iteration. It's frustrating.

@maxcorbeau
Copy link

Similar need here, my use case is previewing individual WordPress pages when using:
https://www.gatsbyjs.org/docs/sourcing-from-wordpress/

The content is managed in WP, the page generation in Gatsby, but would like to visualize individual WP pages as I create/update them without having to rebuild everything.

@gatsbyjs gatsbyjs deleted a comment from amitprajapati7747 Aug 28, 2019
@maxcorbeau
Copy link

maxcorbeau commented Aug 29, 2019

What about allowing to pass a series of node ids to the localhost:8000/__refresh endpoint as body or URL parameters and make those available in gatsby-node.js/createPages to decide to refresh 1 or multiple specific pages? (similar to #5496 (comment) except we replace env variables with URL parameters)

@spik3s
Copy link

spik3s commented Sep 2, 2019

What about allowing to pass a series of node ids to the localhost:8000/__refresh endpoint as body or URL parameters and make those available in gatsby-node.js/createPages to decide to refresh 1 or multiple specific pages? (similar to #5496 (comment) except we replace env variables with URL parameters)

I like that approach, it would make it easier to create hooks in CMS to automatically re-generate content on change when using 3rd party services.

@maxcorbeau
Copy link

maxcorbeau commented Sep 2, 2019

@spik3s : Yes, keeping a REST-based approach instead of environment variables would make Gatsby a lot more interoperable. With Wordpress the integration becomes trivial:

To be placed in functions.php:

function gatsby_refresh( $post_id, $post, $update ) {
    // send $post_id to http://localhost:8000/__refresh
    return true;
}
add_action( 'save_post', 'gatsby_refresh', 10,3 );

@gatsbyjs gatsbyjs deleted a comment from gatsbot bot Jun 7, 2020
@dandv dandv reopened this Jun 7, 2020
@dandv
Copy link
Contributor

dandv commented Jun 7, 2020

Closed by the bot due to inactivity in 2018. Reopening due to activity since then, and no official solution for this very common use case.

@dandv dandv added not stale and removed stale? Issue that may be closed soon due to the original author not responding any more. labels Jun 7, 2020
@LekoArts LekoArts removed the not stale label Jun 8, 2020
@LekoArts
Copy link
Contributor

LekoArts commented Jun 8, 2020

This has been superseded by #5002 and is solved with Incremental Builds. Locally this always worked withing gatsby develop and refresh env var.

@LekoArts LekoArts closed this as completed Jun 8, 2020
@dandv
Copy link
Contributor

dandv commented Jun 9, 2020

Thanks for pointing to #5002, @LekoArts. If I understand correctly,

I believe @jquintozamora was asking in the OP was asking about generating just one page in production.

@LekoArts, can you please clarify how to re-render just one page in production without Gatsby Cloud?

@guifromrio
Copy link

@LekoArts, can you please clarify how to re-render just one page in production without Gatsby Cloud?

I am also interested in this 👀

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

9 participants