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

Experimental: Nuxt 3 Support #255

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1ba3d1c
feat: support for nuxt 3
d3xter-dev Jun 28, 2022
ef52ff1
docs: added more keywords
d3xter-dev Jun 28, 2022
bc8c2b1
chore(release): 3.1.0
d3xter-dev Jun 28, 2022
1d7cd11
chore(release): 3.1.1
d3xter-dev Jun 28, 2022
3c243f1
fix: fixed broken snapshots
d3xter-dev Jun 28, 2022
6367434
fix: was broken in production
d3xter-dev Jul 1, 2022
199ecd1
fix: added tsconfig.json
d3xter-dev Jul 1, 2022
c469ecc
chore(release): 3.1.2
d3xter-dev Jul 1, 2022
79c771d
chore: changing circleci config.yml
d3xter-dev Jul 1, 2022
277b22e
chore: added missing exports to package.json
d3xter-dev Jul 1, 2022
fcc1064
chore(release): 3.1.3
d3xter-dev Jul 1, 2022
4e89a90
chore: changed CHANGELOG.md
d3xter-dev Jul 1, 2022
b12a795
chore: updated the example for dynamic routes in the README.md
d3xter-dev Jul 1, 2022
f282ccd
Update README.md
d3xter-dev Jul 1, 2022
a500efc
Update README.md
d3xter-dev Jul 1, 2022
30418ff
chore(release): 3.1.4
d3xter-dev Jul 1, 2022
4d07701
feat: added test cases for nuxt-i18n and switched to @nuxtjs/i18n-edge
d3xter-dev Jul 6, 2022
f3cc2ae
chore(release): 3.2.0
d3xter-dev Jul 6, 2022
91f515c
Update README.md
d3xter-dev Jul 6, 2022
f12a8dc
Update README.md
d3xter-dev Aug 2, 2022
b705933
fix: nuxt v3.0.0-rc.12 compat
sotnikovse Oct 24, 2022
17979c1
Merge pull request #9 from 5cube/fix/nuxt-rc.12
d3xter-dev Oct 24, 2022
8c207c3
fix(nuxt-rc.12)!: not backwards compatible with old release candidates
d3xter-dev Oct 24, 2022
d1d8d7f
fix(nuxt-rc.12)!: changed example in README.md
d3xter-dev Oct 24, 2022
655581b
Merge pull request #10 from funkenstudio/fix/nuxt-rc.12
d3xter-dev Oct 24, 2022
c566620
chore(release): 4.0.0
d3xter-dev Oct 24, 2022
e515ef9
fix(nuxt 3.0.0): fixes for the latest nuxt release
d3xter-dev Nov 17, 2022
daddc60
chore(nuxt 3.0.0): updated packages to 3.0.0
d3xter-dev Nov 18, 2022
15a0809
chore(release): 4.0.1
d3xter-dev Nov 18, 2022
be94a1a
fix: sitemap generated in wrong directory
d3xter-dev Nov 18, 2022
5981ec7
chore(release): 4.0.2
d3xter-dev Nov 18, 2022
0f922a5
fix: adding pre-rendered routes to sitemap when using nuxi generate
d3xter-dev Nov 19, 2022
48acc42
chore: updated README
d3xter-dev Nov 19, 2022
4b9eb76
chore(release): 4.0.3
d3xter-dev Nov 19, 2022
8c959fe
fix: different sitemaps sharing same routes cache
d3xter-dev Nov 19, 2022
9b4ee8d
chore(release): 4.0.4
d3xter-dev Nov 19, 2022
ef17883
Update README.md
d3xter-dev Sep 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# Test
- run:
name: Tests
command: yarn test
command: yarn nuxt-build-module && yarn test

# Coverage
- run:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
coverage
dist
.nuxt
.commitlintrc.cjs
34 changes: 34 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
extends: [
'@nuxtjs/eslint-config-typescript',
'plugin:prettier/recommended',
'prettier',
'plugin:vue/vue3-recommended',
'eslint:recommended',
'@vue/prettier',
],
rules: {
curly: 'error',
// Allow sparse arrays
'no-sparse-arrays': 'off',
'@typescript-eslint/no-unused-vars': [
'off'
]
},
plugins: ['jest', 'prettier'],
env: {
'jest/globals': true,
},
globals: {
import: 'readonly',
useRuntimeConfig: 'readonly',
},
overrides: [
{
files: ['test/**/*.vue'],
rules: {
'vue/multi-word-component-names': 'off',
},
},
],
}
8 changes: 0 additions & 8 deletions .eslintrc.js

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ node_modules
*.iml
.idea
*.log*
.nuxt
.nuxt/*
!.nuxt/tsconfig.json
.vscode
.DS_Store
coverage
dist
/test/fixture/.nuxt/*
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "\${1}"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint --fix
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn test
79 changes: 79 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,85 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [4.0.4](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v4.0.3...v4.0.4) (2022-11-19)


### Bug Fixes

* different sitemaps sharing same routes cache ([8c959fe](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/8c959fe990a312cb9c089c996640e35c33ed5dac))

### [4.0.3](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v4.0.2...v4.0.3) (2022-11-19)


### Bug Fixes

* adding pre-rendered routes to sitemap when using nuxi generate ([0f922a5](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/0f922a5263128ac67488a8ca420678ba2371c74e))

### [4.0.2](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v4.0.1...v4.0.2) (2022-11-18)


### Bug Fixes

* sitemap generated in wrong directory ([be94a1a](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/be94a1aa771513ab1eb3fda4dfbb0471a4571ee2))

### [4.0.1](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v4.0.0...v4.0.1) (2022-11-18)


### Bug Fixes

* **nuxt 3.0.0:** fixes for the latest nuxt release ([e515ef9](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/e515ef956a35381b21304dfeebeda6c111e17260))

## [4.0.0](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v3.2.0...v4.0.0) (2022-10-24)


### ⚠ BREAKING CHANGES

* **nuxt-rc.12:** not backwards compatible with old release candidates

### Bug Fixes

* **nuxt v3.0.0-rc.12 compat** ([b705933](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/b705933bee8944791fe3dbe3b3687b8e76d06b00))
* **nuxt-rc.12:** changed example in README.md ([d1d8d7f](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/d1d8d7f9083484c341491e49e4eaaf76a794c72d))
* **nuxt-rc.12:** not backwards compatible with old release candidates ([8c207c3](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/8c207c39b07b9406e0024f17ec5b862eb8e71c47))

## [3.2.0](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v3.1.4...v3.2.0) (2022-07-06)


### Features

* added test cases for nuxt-i18n and switched to @nuxtjs/i18n-edge ([4d07701](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/4d07701c3c92d3d0e35689eb980788a4da1d6499))

### [3.1.4](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v3.1.3...v3.1.4) (2022-07-01)

### [3.1.3](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v3.1.2...v3.1.3) (2022-07-01)

### Bug Fixes

* added exports to the package.json

### [3.1.2](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v3.1.1...v3.1.2) (2022-07-01)


### Bug Fixes

* added tsconfig.json ([199ecd1](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/199ecd189d6763c2ebada4e8e437ca79170f02e0))
* fixed broken snapshots ([3c243f1](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/3c243f111592e98ff610fbaef859229b0bd302ad))
* was broken in production ([6367434](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/6367434f7a0a803006f27233c7ac85e6623f467e))

### [3.1.1](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v3.1.0...v3.1.1) (2022-06-28)

## [3.1.0](https://github.com/funken-studio/sitemap-module-nuxt-3/compare/v2.4.0...v3.1.0) (2022-06-28)


### Features

* support for nuxt 3 ([1ba3d1c](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/1ba3d1c763da3c65297dba1b369ec7695203c505))


### Bug Fixes

* return a valid URL from getHostname ([f999d6f](https://github.com/funken-studio/sitemap-module-nuxt-3/commit/f999d6fb137d2d8c8a021994a6e35e42ebd2825c))

## [2.4.0](https://github.com/nuxt-community/sitemap-module/compare/v2.3.2...v2.4.0) (2020-06-25)


Expand Down
118 changes: 116 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# THIS PROJECT IS ARCHIVED
Use https://nuxt.com/modules/sitemap for the newest official version.
#
#
#



[![@nuxtjs/sitemap](docs/static/preview.png)](https://sitemap.nuxtjs.org)

# Sitemap Module

[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/sitemap/latest?style=flat-square)](https://npmjs.com/package/@nuxtjs/sitemap)
[![Downloads](https://img.shields.io/npm/dw/@nuxtjs/sitemap?style=flat-square)](https://npmjs.com/package/@nuxtjs/sitemap)
[![npm (scoped with tag)](https://img.shields.io/npm/v/@funken-studio/sitemap-nuxt-3/latest?style=flat-square)](https://www.npmjs.com/package/@funken-studio/sitemap-nuxt-3)
[![Downloads](https://img.shields.io/npm/dw/@funken-studio/sitemap-nuxt-3?style=flat-square)](https://www.npmjs.com/package/@funken-studio/sitemap-nuxt-3)
[![Build Status](https://img.shields.io/circleci/project/github/nuxt-community/sitemap-module?style=flat-square)](https://app.circleci.com/pipelines/github/nuxt-community/sitemap-module)
[![Coverage Status](https://img.shields.io/codecov/c/github/nuxt-community/sitemap-module?style=flat-square)](https://codecov.io/gh/nuxt-community/sitemap-module)
[![License](https://img.shields.io/npm/l/@nuxtjs/sitemap?style=flat-square)](http://standardjs.com)
Expand All @@ -16,6 +24,112 @@

[📖 **Release Notes**](./CHANGELOG.md)


## Generate sitemap.xml
Normally the sitemap.xml is served via a server middleware / handler, it is only generated in `.output/public` when running `nuxi generate`.

If you want to generate the sitemap.xml on every build, you can set the `generateOnBuild` option to `true` in the module configuration.
(That option might not work if you are using dynamic routes)

```js
// nuxt.config.js
modules: {
...
['@funken-studio/sitemap-nuxt-3', { generateOnBuild: true }],
...
}
```

## Using dynamic routes
- **you are not able to use imports!!**
- see below for a usable workaround:

`nuxt.config.ts`
```js
import dynamicRoutes from './helpers/dynamicRoutes'
...
modules: [
'@funken-studio/sitemap-nuxt-3',
],
sitemap: {
hostname: 'https://example.com',
cacheTime: 1,
routes: dynamicRoutes,
defaults: {
changefreq: 'daily',
priority: 1,
lastmod: new Date().toISOString(),
},
},
...
```

`/helpers/dynamicRoutes`
```js
/**
* since we can't use imports here we just fetch
* all our routes from a custom API endpoint where we can use imports
*/
export default async () => {
return await $fetch('/api/sitemap_routes', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
}

```

`/server/api/sitemap_routes.ts`
```js
import { apiPlugin } from '@storyblok/vue'
import { eventHandler } from 'h3'

/**
* We are using Storyblok as our CMS,
* in order to have all news and testimonials pages in our sitemap
* we need to fetch some from Storyblok
*/
export default eventHandler(async (event) => {
const { req, res } = event
if (req.method !== 'POST') {
res.statusCode = 405
res.end()
return
}
const config = useRuntimeConfig()
const { storyblokApi } = apiPlugin({ apiOptions: config.public.storyblok })
console.log('[vue-sitemap] generate dynamic routes')

const fetchRoutes = async (slug) => {
const routes = []
const pageInfo = await storyblokApi.get(`cdn/stories/?starts_with=${slug}`, {
version: 'published',
per_page: 1,
page: 1,
})

const totalPages = Math.ceil(pageInfo.headers.total / 25)
for (let page = 1; page <= totalPages; page++) {
const pageNews = await storyblokApi.get(`cdn/stories/?starts_with=${slug}`, {
version: 'published',
page: page,
})

for (const news of pageNews.data.stories) {
routes.push(`/${slug}/${news.slug}`)
}

routes.push(`/${slug}/${page}`)
}
return routes
}

return [...(await fetchRoutes('news')), ...(await fetchRoutes('testimonials'))]
})
```

## License

[MIT License](./LICENSE)
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
collectCoverage: true,
collectCoverageFrom: ['lib/**/*.js'],
collectCoverageFrom: ['src/**/*.js'],
testEnvironment: 'node',
}
Loading