2 |
3 | Nuxt module playground!
4 |
5 |
6 |
7 |
9 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "config:base"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_size = 2
5 | indent_style = space
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [*.md]
12 | trim_trailing_whitespace = false
13 |
--------------------------------------------------------------------------------
/playground/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "name": "nuxt-module-feed-playground",
4 | "type": "module",
5 | "scripts": {
6 | "dev": "nuxi dev",
7 | "build": "nuxi build",
8 | "preview": "nuxi preview",
9 | "generate": "nuxi generate"
10 | },
11 | "devDependencies": {
12 | "nuxt": "3.10.3"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.stackblitz/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "scripts": {
4 | "build": "nuxt build",
5 | "dev": "nuxt dev",
6 | "generate": "nuxt generate",
7 | "preview": "nuxt preview",
8 | "postinstall": "nuxt prepare"
9 | },
10 | "devDependencies": {
11 | "nuxt": "3.10.3"
12 | },
13 | "dependencies": {
14 | "nuxt-module-feed": "1.1.4"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/playground/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | export default defineNuxtConfig({
2 | modules: [
3 | '../src/module'
4 | ],
5 | feed: {
6 | sources: [
7 | {
8 | path: '/feed.xml',
9 | type: 'rss2',
10 | cacheTime: 60 * 15
11 | },
12 | {
13 | path: '/feed2.xml',
14 | type: 'rss2',
15 | cacheTime: 60 * 15
16 | },
17 | ]
18 | }
19 | })
20 |
--------------------------------------------------------------------------------
/test/fixtures/feed/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | export default defineNuxtConfig({
2 | modules: [
3 | '../../../src/module'
4 | ],
5 |
6 | feed: {
7 | sources: [
8 | {
9 | path: '/feed.xml',
10 | cacheTime: 60 * 15,
11 | type: 'rss2'
12 | },
13 | {
14 | path: '/feed.atom',
15 | cacheTime: 60 * 15,
16 | type: 'atom1'
17 | },
18 | {
19 | path: '/feed.json',
20 | cacheTime: 60 * 15,
21 | type: 'json1'
22 | }
23 | ]
24 | }
25 | })
26 |
--------------------------------------------------------------------------------
/.stackblitz/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | // https://nuxt.com/docs/api/configuration/nuxt-config
2 | export default defineNuxtConfig({
3 | modules: ['nuxt-module-feed'],
4 | feed: {
5 | sources: [
6 | {
7 | path: '/feed.xml',
8 | cacheTime: 60 * 15,
9 | type: 'rss2'
10 | },
11 | {
12 | path: '/feed.atom',
13 | cacheTime: 60 * 15,
14 | type: 'atom1'
15 | },
16 | {
17 | path: '/feed.json',
18 | cacheTime: 60 * 15,
19 | type: 'json1'
20 | }
21 | ]
22 | }
23 | })
24 |
--------------------------------------------------------------------------------
/src/types.ts:
--------------------------------------------------------------------------------
1 | import type { Feed } from 'feed'
2 |
3 | export type { Feed } from 'feed'
4 |
5 | export type FeedType = 'rss2' | 'atom1' | 'json1'
6 |
7 | export interface SourceOptions {
8 | path: string;
9 | type: FeedType;
10 | cacheTime: number;
11 | }
12 |
13 | export interface ModuleOptions {
14 | sources: SourceOptions[];
15 | }
16 |
17 | export interface NitroCtx {
18 | feed: Feed;
19 | options: SourceOptions;
20 | }
21 |
22 | declare module 'nitropack' {
23 | interface NitroRuntimeHooks {
24 | 'feed:generate': (ctx: NitroCtx) => void;
25 | }
26 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Dependencies
2 | node_modules
3 |
4 | # Logs
5 | *.log*
6 |
7 | # Temp directories
8 | .temp
9 | .tmp
10 | .cache
11 |
12 | # Yarn
13 | **/.yarn/cache
14 | **/.yarn/*state*
15 |
16 | # Generated dirs
17 | dist
18 |
19 | # Nuxt
20 | .nuxt
21 | .output
22 | .vercel_build_output
23 | .build-*
24 | .env
25 | .netlify
26 |
27 | # Env
28 | .env
29 |
30 | # Testing
31 | reports
32 | coverage
33 | *.lcov
34 | .nyc_output
35 |
36 | # VSCode
37 | .vscode/*
38 | !.vscode/settings.json
39 | !.vscode/tasks.json
40 | !.vscode/launch.json
41 | !.vscode/extensions.json
42 | !.vscode/*.code-snippets
43 |
44 | # Intellij idea
45 | *.iml
46 | .idea
47 |
48 | # OSX
49 | .DS_Store
50 | .AppleDouble
51 | .LSOverride
52 | .AppleDB
53 | .AppleDesktop
54 | Network Trash Folder
55 | Temporary Items
56 | .apdisk
57 |
--------------------------------------------------------------------------------
/test/feed.test.ts:
--------------------------------------------------------------------------------
1 | import { describe, it, expect } from 'vitest'
2 | import { fileURLToPath } from 'node:url'
3 | import { setup, $fetch } from '@nuxt/test-utils'
4 |
5 | describe('ssr', async () => {
6 | await setup({
7 | rootDir: fileURLToPath(new URL('./fixtures/feed', import.meta.url)),
8 | server: true
9 | })
10 |
11 | it('renders the rss feed', async () => {
12 | const html = await $fetch('/feed.xml')
13 | expect(await html.text()).toMatchSnapshot()
14 | })
15 |
16 | it('renders the atom feed', async () => {
17 | const html = await $fetch('/feed.atom')
18 | expect(await html.text()).toMatchSnapshot()
19 | })
20 |
21 | it('renders the json feed', async () => {
22 | const html = await $fetch('/feed.json')
23 | expect(html).toMatchSnapshot()
24 | })
25 | })
26 |
27 |
--------------------------------------------------------------------------------
/.stackblitz/README.md:
--------------------------------------------------------------------------------
1 | # Nuxt 3 Minimal Starter
2 |
3 | Look at the [Nuxt 3 documentation](https://nuxt.com/docs/getting-started/introduction) to learn more.
4 |
5 | ## Setup
6 |
7 | Make sure to install the dependencies:
8 |
9 | ```bash
10 | # yarn
11 | yarn install
12 |
13 | # npm
14 | npm install
15 |
16 | # pnpm
17 | pnpm install
18 | ```
19 |
20 | ## Development Server
21 |
22 | Start the development server on http://localhost:3000
23 |
24 | ```bash
25 | npm run dev
26 | ```
27 |
28 | ## Production
29 |
30 | Build the application for production:
31 |
32 | ```bash
33 | npm run build
34 | ```
35 |
36 | Locally preview production build:
37 |
38 | ```bash
39 | npm run preview
40 | ```
41 |
42 | Check out the [deployment documentation](https://nuxt.com/docs/getting-started/deployment) for more information.
43 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Miha Sedej
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | # Runs on pushes targeting the default branch
5 | push:
6 | branches: ["*"]
7 |
8 | # Allows you to run this workflow manually from the Actions tab
9 | workflow_dispatch:
10 |
11 | jobs:
12 | # Build job
13 | build:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout
17 | uses: actions/checkout@v4
18 | - name: Setup Node
19 | uses: actions/setup-node@v4
20 | with:
21 | node-version: "18"
22 | cache: ${{ steps.detect-package-manager.outputs.manager }}
23 | - name: Restore cache
24 | uses: actions/cache@v4
25 | with:
26 | path: |
27 | dist
28 | .nuxt
29 | key: ${{ runner.os }}-nuxt-build-${{ hashFiles('dist') }}
30 | restore-keys: |
31 | ${{ runner.os }}-nuxt-build-
32 | - name: Install pnpm
33 | run: npm install -g pnpm
34 | - name: Install dependencies
35 | run: pnpm install
36 | - name: Prepare env
37 | run: pnpm run dev:prepare
38 | - name: Lint
39 | run: pnpm run lint
40 | - name: Tests
41 | run: pnpm run test
42 |
--------------------------------------------------------------------------------
/src/module.ts:
--------------------------------------------------------------------------------
1 | import { defineNuxtModule, createResolver, addServerHandler, addTemplate, addPrerenderRoutes } from '@nuxt/kit'
2 | import type { ModuleOptions, SourceOptions } from './types';
3 |
4 | export * from './types'
5 |
6 | export default defineNuxtModule