2 |
3 | Nuxt module playground!
4 |
5 |
6 |
7 |
9 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/playground/server/plugins/feed.ts:
--------------------------------------------------------------------------------
1 | import type { NitroCtx, Feed } from '../../../src/module'
2 |
3 | export default defineNitroPlugin((nitroApp) => {
4 | nitroApp.hooks.hook('feed:generate', async ({ feed, options }: NitroCtx) => {
5 | switch(options.path) {
6 | case '/feed.xml': {
7 | createTestFeed(feed)
8 | break
9 | }
10 | case '/feed2.xml': {
11 | createTestFeed(feed)
12 | break
13 | }
14 | }
15 | })
16 |
17 | function createTestFeed(feed: Feed) {
18 | feed.options = {
19 | id: 'Test Feed',
20 | title: 'Test Feed',
21 | copyright: 'Test company'
22 | }
23 |
24 | type Post = {
25 | title: string;
26 | url: string;
27 | description: string;
28 | content: string;
29 | date: Date;
30 | image: string;
31 | };
32 |
33 | const posts: Post[] = [
34 | {
35 | title: "Post 1",
36 | url: "https://example.com/post-1",
37 | description: "This is the first post",
38 | content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
39 | date: new Date("2022-01-01"),
40 | image: "https://example.com/images/post1.jpg",
41 | },
42 | {
43 | title: "Post 2",
44 | url: "https://example.com/post-2",
45 | description: "This is the second post",
46 | content: "Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
47 | date: new Date("2022-01-05"),
48 | image: "https://example.com/images/post2.jpg",
49 | },
50 | {
51 | title: "Post 3",
52 | url: "https://example.com/post-3",
53 | description: "This is the third post",
54 | content: "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
55 | date: new Date("2022-01-10"),
56 | image: "https://example.com/images/post3.jpg",
57 | },
58 | {
59 | title: "Post 4",
60 | url: "https://example.com/post-4",
61 | description: "This is the fourth post",
62 | content: "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",
63 | date: new Date("2022-01-15"),
64 | image: "https://example.com/images/post4.jpg",
65 | },
66 | {
67 | title: "Post 5",
68 | url: "https://example.com/post-5",
69 | description: "This is the fifth post",
70 | content: "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
71 | date: new Date("2022-01-20"),
72 | image: "https://example.com/images/post5.jpg",
73 | },
74 | ];
75 |
76 | posts.forEach(post => {
77 | feed.addItem({
78 | title: post.title,
79 | id: post.url,
80 | link: post.url,
81 | description: post.description,
82 | content: post.content,
83 | date: post.date
84 | })
85 | })
86 |
87 | feed.addCategory('Nuxt.js')
88 |
89 | feed.addContributor({
90 | name: 'Miha Sedej',
91 | email: 'sedej.miha@gmail.com',
92 | link: 'https://tresko.dev/'
93 | })
94 | }
95 | })
--------------------------------------------------------------------------------
/playground/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../.nuxt/tsconfig.server.json"
3 | }
4 |
--------------------------------------------------------------------------------
/playground/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./.nuxt/tsconfig.json"
3 | }
4 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "config:base"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------
/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