Refactor to fix bug - implement static site generation - #17
Refactor to fix bug - implement static site generation#17JuanPabloDiaz wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the project to use static site generation instead of server‐side rendering, reducing serverless function calls and optimizing performance. Key changes include updating the Astro configuration to output static files, implementing getStaticPaths functions for multiple dynamic pages and fragments, and refactoring data fetching to use preloaded JSON data.
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/tv/[id].astro | Added getStaticPaths using combined TV show data and passed props to TvDetails. |
| src/pages/podcasts/[id].astro | Implemented getStaticPaths and updated PodcastDetailsFragment usage. |
| src/pages/people/[id].astro | Added getStaticPaths that extracts unique person IDs from movie credits. |
| src/pages/movies/[id].astro | Added getStaticPaths to generate unique movie paths and passed movie data as props. |
| src/pages/games/[slug].astro | Introduced getStaticPaths for game pages with improved error handling. |
| src/pages/fragments/TvDetails/[id].astro | Updated getStaticPaths and adjusted data processing with optional chaining. |
| src/pages/fragments/PodcastList/index.astro | Replaced Astro.glob with direct JSON import for podcasts data. |
| src/pages/fragments/PodcastDetails/[id].astro | Refactored to use preloaded podcast data via static props. |
| src/pages/fragments/PersonDetails/[id].astro | Added static paths generation for person details from movie credits. |
| src/pages/fragments/MovieDetails/[id].astro | Updated static path generation and data formatting using the preloaded movie JSON. |
| src/pages/fragments/GameDetails/[slug].astro | Refactored static generation with improved error handling and prop usage. |
| src/pages/fragments/BookDetails/[id].astro | Implemented getStaticPaths for book details with preloaded JSON data. |
| src/pages/books/[id].astro | Added getStaticPaths to predefine book paths for SSG and removed SSR comments. |
| src/pages/artists/[mbid].astro | Added getStaticPaths for artist pages using preloaded artist data. |
| astro.config.mjs | Updated configuration to output static files and removed Vercel adapter. |
Comments suppressed due to low confidence (1)
src/pages/fragments/BookDetails/[id].astro:21
- Consider destructuring 'bookData' from Astro.props (like in other pages) to leverage the preloaded JSON data and avoid runtime fetches.
const { id } = Astro.params; // Get the book's OpenLibrary Work ID from the URL
| if (tvShowDetailsJson && tvShowDetailsJson.regular) { | ||
| return tvShowDetailsJson.regular.map(show => ({ |
There was a problem hiding this comment.
For consistency with the main TV page, consider combining 'tvShowDetailsJson.spanish' with 'tvShowDetailsJson.regular' in the static path generation.
| if (tvShowDetailsJson && tvShowDetailsJson.regular) { | |
| return tvShowDetailsJson.regular.map(show => ({ | |
| if (tvShowDetailsJson && (tvShowDetailsJson.regular || tvShowDetailsJson.spanish)) { | |
| const combinedShows = [ | |
| ...(tvShowDetailsJson.regular || []), | |
| ...(tvShowDetailsJson.spanish || []) | |
| ]; | |
| return combinedShows.map(show => ({ |
| // } | ||
| // return []; // Fallback to empty paths if error or no data | ||
| // } | ||
| // For static site generation, getStaticPaths is required for dynamic routing |
There was a problem hiding this comment.
Consider passing the full book data as props in getStaticPaths to maintain consistency with other dynamic routes and eliminate potential runtime fetching.
✅ Deploy Preview for jpfav ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
fixes #16
This pull request transitions the project from server-side rendering (SSR) to static site generation (SSG) and includes changes to predefine static paths for various dynamic routes. It modifies the
astro.config.mjsfile to set the output tostaticand introducesgetStaticPathsfunctions across multiple pages and fragments to enable SSG. Additionally, it refactors how data is fetched and passed to components, replacing runtime API calls with preloaded JSON data.Configuration Update:
astro.config.mjs: Changedoutputfrom'server'to'static'to optimize for static site generation and reduce serverless function calls. Removed the Vercel adapter as it is no longer needed for SSG.Static Paths Implementation for Pages:
src/pages/artists/[mbid].astro: AddedgetStaticPathsto generate paths for artist pages based onartistDetails.json. (src/pages/artists/[mbid].astroR4-R15)src/pages/books/[id].astro: ImplementedgetStaticPathsto predefine paths for book pages usingmyFavBooks.json. (src/pages/books/[id].astroL9-R26)src/pages/games/[slug].astro: AddedgetStaticPathsto generate paths for game pages usinggameDetails.json. (src/pages/games/[slug].astroR4-R22)src/pages/movies/[id].astro: IntroducedgetStaticPathsto predefine paths for movie pages, consolidating data from all genres inmovieDetails.json. (src/pages/movies/[id].astroR4-R26)src/pages/people/[id].astro: AddedgetStaticPathsto extract unique person IDs from movie credits inmovieDetails.json. (src/pages/people/[id].astroR4-R50)src/pages/podcasts/[id].astro: ImplementedgetStaticPathsto generate paths for podcast pages based onpodcastDetails.json. (src/pages/podcasts/[id].astroR4-R20)src/pages/tv/[id].astro: AddedgetStaticPathsto generate paths for TV show pages, combining regular and Spanish shows fromtvShowDetails.json. (src/pages/tv/[id].astroR4-R25)Static Paths Implementation for Fragments:
src/pages/fragments/BookDetails/[id].astro: AddedgetStaticPathsto predefine paths for book detail fragments usingmyFavBooks.json. (src/pages/fragments/BookDetails/[id].astroR2-R20)src/pages/fragments/GameDetails/[slug].astro: IntroducedgetStaticPathsto predefine paths for game detail fragments usinggameDetails.json. (src/pages/fragments/GameDetails/[slug].astroR3-R32)src/pages/fragments/MovieDetails/[id].astro: AddedgetStaticPathsto predefine paths for movie detail fragments, utilizingmovieDetails.json. (src/pages/fragments/MovieDetails/[id].astroR3-R67)src/pages/fragments/PersonDetails/[id].astro: ImplementedgetStaticPathsto extract unique person IDs from movie credits for person detail fragments. (src/pages/fragments/PersonDetails/[id].astroR2-R41)src/pages/fragments/PodcastDetails/[id].astro: AddedgetStaticPathsto predefine paths for podcast detail fragments usingpodcastDetails.json. (src/pages/fragments/PodcastDetails/[id].astroL2-R33)These changes collectively enable static site generation, improve performance, and reduce reliance on runtime API calls by leveraging preloaded JSON data for dynamic routing.