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

Does not recognise adapter-vercel build directory #16

Open
mstibbard opened this issue Oct 5, 2021 · 7 comments
Open

Does not recognise adapter-vercel build directory #16

mstibbard opened this issue Oct 5, 2021 · 7 comments
Labels
documentation Improvements or additions to documentation

Comments

@mstibbard
Copy link

Issue

svelte-sitemap does not recognise the build directory when using adapter-vercel, regardless of what output directory is provided.

Details

Error

× Make sure you are using this script as 'postbuild' so '.vercel_build_output' folder was successfully created before running this script. See https://github.com/bartholomej/svelte-sitemap#readme

Scripts

Relevant excerpt from package.json:

"scripts": {
    "postbuild": "yarn generate:sitemap",
    "generate:sitemap": "svelte-sitemap -d https://www.example.com -o .vercel_build_output"
}

Versions

"svelte-sitemap": "^2.1.1"
"@sveltejs/adapter-vercel": "next" (version "1.0.0-next.28" in yarn.lock)
"@sveltejs/kit": "next" (version "1.0.0-next.159" in yarn.lock)

I've tried adding ls -a in the postbuild script prior to running generate:sitemap and the output includes .vercel_build_output, so the directory does exist

@mstibbard
Copy link
Author

This may be working as intended? The readme specifies this is for static sitemaps, which I understood as meaning all routes are known, but I think it means the site must not be SSR.

I probably needed more sleep before raising this issue 😅 I'll leave it in case it helps someone though.

For anyone that runs into this "issue" with their SSR site, you should be creating an endpoint (e.g. routes/sitemap.xml.ts) and dynamically generating your sitemap there.

E.g.

import type { RequestHandler } from '@sveltejs/kit';
import { url, pages } from '$lib/constants'; // or wherever your relevant data is

export const get: RequestHandler = async () => {
  const headers = {
    'Cache-Control': 'max-age=0, s-maxage=3600',
    'Content-Type': 'application/xml'
  };
  const body = `<?xml version="1.0" encoding="UTF-8" ?>
  <urlset
    xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
  >
    <url>
      <loc>${url}</loc>
      <changefreq>always</changefreq>
      <priority>1.0</priority>
    </url>
    ${pages
      .map(
        (page) => `
    <url>
      <loc>${url}/${page}</loc>
      <changefreq>daily</changefreq>
      <priority>0.5</priority>
    </url>
    `
      )
      .join('')}
  </urlset>`
    
  return {
    headers,
    body
  };
};

@baisong
Copy link

baisong commented Nov 4, 2021

I was able to get this working with...

"scripts": {
    ...
    "postbuild": "yarn generate:sitemap",
    "generate:sitemap": "svelte-sitemap --domain [mydomain]; cp build/sitemap.xml static/sitemap.xml"
  }

...And these vercel app settings:
Screenshot from 2021-11-04 13-55-23

@dev-ofty
Copy link

it's odd, I'm trying method from @baisong, but I keep on having these errors:

yarn run v1.22.17
--
15:49:55.732 | $ svelte-sitemap --domain https://mydomain.vercel.app; cp build/sitemap.xml static/sitemap.xml
15:49:55.894 | > Using svelte-sitemap
15:49:55.901 | × Folder 'build/' doesn't exist.
15:49:55.901 | Make sure you are using this library as 'postbuild' so 'build/' folder was successfully created before running this script. See https://github.com/bartholomej/svelte-sitemap#readme
15:49:55.901 | × File 'build/sitemap.xml' could not be created.
15:49:55.904 | cp: cannot stat ‘build/sitemap.xml’: No such file or directory
15:49:55.916 | error Command failed with exit code 1.
15:49:55.916 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
15:49:55.940 | Error: Command "npm run build" exited with 1

I made sure the Buld & Developments Settings matches…

@bartholomej
Copy link
Owner

@dev-ofty And have you seen this? #31 (comment)

@dev-ofty
Copy link

@bartholomej Oh thank you, obviously i didn't check enough. Thank you.

@bartholomej
Copy link
Owner

@dev-ofty Just let us know if this is the solution for you ;) If so, I will mention it in readme.

@candidosales
Copy link

I found a good solution ...

"scripts": {
		"postbuild": "npx svelte-sitemap --out-dir .vercel/output/static --domain https://yourdomain.com; cp .vercel/output/static/sitemap.xml static/sitemap.xml"
		}

CleanShot 2023-02-16 at 22 14 19@2x

@bartholomej bartholomej added the documentation Improvements or additions to documentation label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants