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

feat(vite-plugin-nitro): add initial support for sitemap generation #497

Conversation

QuantariusRay
Copy link
Contributor

@QuantariusRay QuantariusRay commented Jul 3, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Which package are you modifying?

  • vite-plugin-angular
  • vite-plugin-nitro
  • astro-angular
  • create-analog
  • router
  • platform
  • content
  • nx-plugin
  • trpc

What is the current behavior?

Closes #307

What is the new behavior?

Added a config property in pre-render (though, now, that could probably change in the end). This ends up being a property that is just used to generate the domain name needed... I'm open to changing that to a top-level property, I think it'll make more sense.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

[optional] What gif

none yet :(

Q added 2 commits July 2, 2023 22:28
Add sitemap generation for users upon passing a small config object.
Followup - removed unnecessary property in vite.config.ts files in apps
@netlify
Copy link

netlify bot commented Jul 3, 2023

Deploy Preview for analog-app ready!

Name Link
🔨 Latest commit 3fd5deb
🔍 Latest deploy log https://app.netlify.com/sites/analog-app/deploys/64a371120e4ef50008ca0987
😎 Deploy Preview https://deploy-preview-497--analog-app.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jul 3, 2023

Deploy Preview for analog-blog ready!

Name Link
🔨 Latest commit 3fd5deb
🔍 Latest deploy log https://app.netlify.com/sites/analog-blog/deploys/64a37112d9ff900008a75366
😎 Deploy Preview https://deploy-preview-497--analog-blog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jul 3, 2023

Deploy Preview for analog-docs ready!

Name Link
🔨 Latest commit 3fd5deb
🔍 Latest deploy log https://app.netlify.com/sites/analog-docs/deploys/64a3711274beef0008d0d099
😎 Deploy Preview https://deploy-preview-497--analog-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@QuantariusRay QuantariusRay marked this pull request as ready for review July 3, 2023 03:48
@brandonroberts brandonroberts changed the title Q/feature/implement sitemap generator feat(vite-plugin-nitro): add initial support for sitemap generation Jul 3, 2023
Copy link
Member

@brandonroberts brandonroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Minor changes

@@ -26,6 +26,9 @@ export default defineConfig(() => {
'/blog/2022-12-31-my-second-post',
];
},
sitemap: {
domain: 'example.com/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use the deployment URL

Suggested change
domain: 'example.com/',
domain: 'https://analog-blog.netlify.app/',


if (routeList.length) {
const sitemapData: PagesJson[] = routeList.map((page: string) => ({
page: `https://www.${sitemapConfig.domain}${page.replace(/^\/+/g, '')}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the user customize the entire host, for example https://myblog.dev

Suggested change
page: `https://www.${sitemapConfig.domain}${page.replace(/^\/+/g, '')}`,
page: `${sitemapConfig.host}${page.replace(/^\/+/g, '')}`,

@@ -32,6 +32,9 @@ export default defineConfig(({ mode }) => {
apiPrefix: 'api',
prerender: {
routes: ['/', '/cart'],
sitemap: {
domain: 'example.com/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the custom base URL for this example

Suggested change
domain: 'example.com/',
domain: process.env['VITE_ANALOG_PUBLIC_BASE_URL'],

@@ -155,6 +156,7 @@
"vite-plugin-eslint": "^1.8.1",
"vite-tsconfig-paths": "4.2.0",
"vitest": "0.32.2",
"webpack-bundle-analyzer": "^4.7.0"
"webpack-bundle-analyzer": "^4.7.0",
"xmlbuilder2": "^3.0.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be added to the dependencies in packages/platform/package.json also

}

export interface SitemapConfig {
domain: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
domain: string;
host: string;


const mapPath = `${path.resolve(
'dist',
config.root!,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a fallback root

Suggested change
config.root!,
config.root || '.',

@@ -0,0 +1,73 @@
import { SitemapConfig } from './options';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put local imports last

Suggested change
import { SitemapConfig } from './options';
import { SitemapConfig } from './options';

Q and others added 2 commits July 3, 2023 19:03
Followup - Fix PR comments. Update config and properties in the config files with examples.
@QuantariusRay
Copy link
Contributor Author

Thanks for the review. Made requested changes.

Followup - Add check for slash to display or not to avoid doubles
@brandonroberts brandonroberts merged commit 8485648 into analogjs:main Jul 4, 2023
@brandonroberts
Copy link
Member

Thanks! @allcontributors add @QuantariusRay for code

@allcontributors
Copy link
Contributor

@brandonroberts

I've put up a pull request to add @QuantariusRay! 🎉

Villanuevand pushed a commit to Villanuevand/analog that referenced this pull request Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: add sitemap generation support
2 participants