-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext-sitemap.config.js
More file actions
86 lines (76 loc) · 3.15 KB
/
Copy pathnext-sitemap.config.js
File metadata and controls
86 lines (76 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const { createClient: createSupabaseClient } = require('@supabase/supabase-js')
const { createClient: createLibsqlClient } = require('@libsql/client')
// Supabaseクライアント (Store用)
const supabase = createSupabaseClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
)
// Tursoクライアント (Wiki用)
const turso = createLibsqlClient({
url: process.env.NEXT_PUBLIC_TURSO_DATABASE_URL,
authToken: process.env.NEXT_PUBLIC_TURSO_AUTH_TOKEN,
})
/** @type {import('next-sitemap').IConfig} */
module.exports = {
siteUrl: 'https://asakura-wiki.vercel.app',
generateRobotsTxt: true,
sitemapSize: 7000,
additionalPaths: async () => {
// ==========================================
// 1. 新エンジン (Turso) から Wiki ページを取得
// ==========================================
const wikiPaths = []
try {
// wiki_pages テーブルから全ページの情報を取得
const result = await turso.execute(
"SELECT wiki_slug, slug FROM wiki_pages"
)
for (let i = 0;i < result.rows.length;i++) {
const wikiSlug = result.rows[i].wiki_slug;
const pageSlug = result.rows[i].slug;
if (wikiSlug && pageSlug) {
// FrontPage はルート扱い (/wiki/slug)、それ以外はサブパス
const path = pageSlug === 'FrontPage'
? `/wiki/${wikiSlug}`
: `/wiki/${wikiSlug}/${pageSlug}`
wikiPaths.push({
loc: path,
lastmod: new Date().toISOString(), // DBの更新日時を使用
changefreq: 'daily',
priority: 0.8,
})
}
}
} catch (e) {
console.error('Sitemap Wiki (Turso) Error:', e)
}
// ==========================================
// 2. 既存の Store (Supabase) データを取得
// ==========================================
const { data: apps_data } = await supabase.from("store.apps").select("appid")
const { data: devs_data } = await supabase.from("store.developers").select("developer_id")
const storePaths = (apps_data || []).map(app => ({
loc: `/store/details/${app.appid}`,
lastmod: new Date().toISOString(),
changefreq: 'daily',
priority: 0.6,
})).concat((devs_data || []).map(dev => ({
loc: `/store/developers/${dev.developer_id}`,
lastmod: new Date().toISOString(),
changefreq: 'daily',
priority: 0.5,
})))
return [...wikiPaths, ...storePaths, {
loc: "/api/html",
lastmod: new Date().toISOString(),
changefreq: 'daily',
priority: 0.6,
},
{
loc: "/special_wiki/14ninstudio/不審者が出た時の対処法",
lastmod: new Date().toISOString(),
changefreq: 'daily',
priority: 0.6,
}]
},
}