jeawin-astro 1.1.13 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/env.d.ts +1 -0
- package/src/integrations/jeawin-runtime-config/index.ts +58 -2
- package/src/pages/clear_cache.ts +7 -0
- package/src/pages/manifest.json.ts +55 -0
- package/src/pages/opensearch.xml.ts +32 -0
- package/src/pages/robots.txt.ts +11 -0
- package/src/pages/rss.xml.ts +34 -0
- package/src/pages/site.webmanifest.ts +31 -0
- package/src/pages/sitemap.txt.ts +15 -0
- package/src/pages/sitemap.xml.ts +28 -0
- package/src/pages/sitemap.xsl.ts +131 -0
package/package.json
CHANGED
package/src/env.d.ts
CHANGED
|
@@ -7,20 +7,76 @@
|
|
|
7
7
|
* @email chaegumi@jeawin.com
|
|
8
8
|
* @filesource
|
|
9
9
|
*/
|
|
10
|
-
import {defineIntegration, addVirtualImports} from "astro-integration-kit";
|
|
10
|
+
import {defineIntegration, addVirtualImports,createResolver} from "astro-integration-kit";
|
|
11
11
|
const cacache = await import('cacache');
|
|
12
12
|
export default defineIntegration({
|
|
13
13
|
name: "jeawin-runtime-config",
|
|
14
14
|
setup({name}) {
|
|
15
|
+
const { resolve } = createResolver(import.meta.url);
|
|
15
16
|
return {
|
|
16
17
|
hooks:{
|
|
17
18
|
"astro:config:setup":(params) => {
|
|
19
|
+
|
|
20
|
+
const {config, addMiddleware, injectRoute} = params;
|
|
18
21
|
addVirtualImports(params, {
|
|
19
22
|
name,
|
|
20
23
|
imports:{
|
|
21
24
|
'virtual:jeawin-runtime-config/config': `export default ${JSON.stringify(params.config)}`
|
|
22
25
|
}
|
|
23
|
-
})
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// addMiddleware({
|
|
29
|
+
// entrypoint: '',
|
|
30
|
+
// order:'pre'
|
|
31
|
+
// });
|
|
32
|
+
|
|
33
|
+
injectRoute({
|
|
34
|
+
pattern: '/robots.txt',
|
|
35
|
+
entrypoint: resolve('../../pages/robots.txt.ts'),
|
|
36
|
+
prerender: true
|
|
37
|
+
});
|
|
38
|
+
injectRoute({
|
|
39
|
+
pattern: '/clear_cache',
|
|
40
|
+
entrypoint: resolve('../../pages/clear_cache.ts'),
|
|
41
|
+
prerender: true
|
|
42
|
+
});
|
|
43
|
+
injectRoute({
|
|
44
|
+
pattern: '/manifest.json',
|
|
45
|
+
entrypoint: resolve('../../pages/manifest.json.ts'),
|
|
46
|
+
prerender: true
|
|
47
|
+
});
|
|
48
|
+
injectRoute({
|
|
49
|
+
pattern: '/opensearch.xml',
|
|
50
|
+
entrypoint: resolve('../../pages/opensearch.xml.ts'),
|
|
51
|
+
prerender: true
|
|
52
|
+
});
|
|
53
|
+
injectRoute({
|
|
54
|
+
pattern: '/rss.xml',
|
|
55
|
+
entrypoint: resolve('../../pages/rss.xml.ts'),
|
|
56
|
+
prerender: true
|
|
57
|
+
});
|
|
58
|
+
injectRoute({
|
|
59
|
+
pattern: '/site.webmanifest',
|
|
60
|
+
entrypoint: resolve('../../pages/site.webmanifest.ts'),
|
|
61
|
+
prerender: true
|
|
62
|
+
});
|
|
63
|
+
injectRoute({
|
|
64
|
+
pattern: '/sitemap.txt',
|
|
65
|
+
entrypoint: resolve('../../pages/sitemap.txt.ts'),
|
|
66
|
+
prerender: true
|
|
67
|
+
});
|
|
68
|
+
injectRoute({
|
|
69
|
+
pattern: '/sitemap.xml',
|
|
70
|
+
entrypoint: resolve('../../pages/sitemap.xml.ts'),
|
|
71
|
+
prerender: true
|
|
72
|
+
});
|
|
73
|
+
injectRoute({
|
|
74
|
+
pattern: '/sitemap.xsl',
|
|
75
|
+
entrypoint: resolve('../../pages/sitemap.xsl.ts'),
|
|
76
|
+
prerender: true
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
|
|
24
80
|
},
|
|
25
81
|
"astro:build:start":() => {
|
|
26
82
|
// build之前,清空一下cacache缓存目录
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
|
|
3
|
+
export const GET:APIRoute = async ({site, locals}) => {
|
|
4
|
+
const site_options = locals.site_options;
|
|
5
|
+
const siteinfo = locals.siteinfo;
|
|
6
|
+
|
|
7
|
+
const icon1 = await locals.jeawinapi.get_theme_image_url({
|
|
8
|
+
image_url: site_options.sitelogo,
|
|
9
|
+
params_json: {
|
|
10
|
+
w:192,
|
|
11
|
+
h:192,
|
|
12
|
+
fm:'webp',
|
|
13
|
+
fit:'fill'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const icon2 = await locals.jeawinapi.get_theme_image_url({
|
|
17
|
+
image_url: site_options.sitelogo,
|
|
18
|
+
params_json: {
|
|
19
|
+
w:512,
|
|
20
|
+
h:512,
|
|
21
|
+
fm:'webp',
|
|
22
|
+
fit: 'fill'
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return new Response(JSON.stringify({
|
|
27
|
+
"short_name": siteinfo.site_uri,
|
|
28
|
+
"name": siteinfo.site_name,
|
|
29
|
+
"icons": [
|
|
30
|
+
{
|
|
31
|
+
"src": icon1,
|
|
32
|
+
"type": "image/webp",
|
|
33
|
+
"sizes": "192x192",
|
|
34
|
+
"purpose": "any maskable"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"src": icon2,
|
|
38
|
+
"type": "image/webp",
|
|
39
|
+
"sizes": "512x512"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"id": siteinfo.site_uri,
|
|
43
|
+
"start_url": site,
|
|
44
|
+
"background_color": siteinfo.theme_color,
|
|
45
|
+
"display": "standalone",
|
|
46
|
+
"scope": "/",
|
|
47
|
+
"theme_color": siteinfo.theme_color,
|
|
48
|
+
"description": site_options.logo_title
|
|
49
|
+
}), {
|
|
50
|
+
status: 200,
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
|
|
3
|
+
export const GET:APIRoute = ({site, locals}) => {
|
|
4
|
+
const site_options = locals.site_options;
|
|
5
|
+
const siteinfo = locals.siteinfo;
|
|
6
|
+
|
|
7
|
+
let xml = `<?xml version="1.0" ?>
|
|
8
|
+
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
|
|
9
|
+
<ShortName>${siteinfo.site_name}</ShortName>
|
|
10
|
+
<Description>Search in site ${siteinfo.site_name}</Description>
|
|
11
|
+
<Url type="text/html" method="get" template="${site}search.html">
|
|
12
|
+
<Param name="opensearch" value="1"/>
|
|
13
|
+
<Param name="q" value="{searchTerms}"/>
|
|
14
|
+
</Url>`;
|
|
15
|
+
|
|
16
|
+
if(site_options.sitelogo.indexOf('.ico') === -1){
|
|
17
|
+
xml += `<Image width="16" height="16">${site_options.sitelogo}</Image>`;
|
|
18
|
+
}else{
|
|
19
|
+
xml += `<Image type="image/x-icon" width="16" height="16">${site_options.sitelogo}</Image>`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
xml += `
|
|
23
|
+
<InputEncoding>UTF-8</InputEncoding>
|
|
24
|
+
<moz:SearchForm>${site}search.html</moz:SearchForm>
|
|
25
|
+
</OpenSearchDescription>`;
|
|
26
|
+
return new Response(xml,{
|
|
27
|
+
status: 200,
|
|
28
|
+
headers: {
|
|
29
|
+
"Content-Type": "application/xml"
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
|
|
3
|
+
const getRobotsTxt = (sitemapURL: URL) => `User-agent: *
|
|
4
|
+
Allow: /
|
|
5
|
+
Sitemap: ${sitemapURL.href}
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export const GET:APIRoute = ({site}) => {
|
|
9
|
+
const sitemapURL = new URL('sitemap.xml', site);
|
|
10
|
+
return new Response(getRobotsTxt(sitemapURL));
|
|
11
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import rss from '@astrojs/rss';
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import type { APIRoute } from 'astro';
|
|
4
|
+
import { render_url } from '../scripts/util.js';
|
|
5
|
+
|
|
6
|
+
export const GET:APIRoute = async ({site, locals}) => {
|
|
7
|
+
|
|
8
|
+
const node_results: any = await locals.jeawinapi.get_nodes({
|
|
9
|
+
limit_type: 'limit',
|
|
10
|
+
sort: 'node_created',
|
|
11
|
+
sortorder: 'desc',
|
|
12
|
+
page_size: 10,
|
|
13
|
+
per_page: 10
|
|
14
|
+
});
|
|
15
|
+
// console.log(node_results);
|
|
16
|
+
const site_options = locals.site_options;
|
|
17
|
+
|
|
18
|
+
let items: any = [];
|
|
19
|
+
node_results.nodes.forEach((node: any) => {
|
|
20
|
+
items.push({
|
|
21
|
+
title: node.node_title,
|
|
22
|
+
pubDate: dayjs.unix(node.node_created).format('YYYY-MM-DD HH:mm:ss'),
|
|
23
|
+
description: node.content,
|
|
24
|
+
link: render_url(node.node_uri, locals.base)
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
return rss({
|
|
29
|
+
title: site_options.sitename,
|
|
30
|
+
description: site_options.seo_description,
|
|
31
|
+
site: String(site),
|
|
32
|
+
items:items,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
export const GET:APIRoute = async ({site, locals}) => {
|
|
5
|
+
const site_options = locals.site_options;
|
|
6
|
+
const siteinfo = locals.siteinfo;
|
|
7
|
+
const icon1 = await locals.jeawinapi.get_theme_image_url({
|
|
8
|
+
image_url:site_options.sitelogo,
|
|
9
|
+
params_json:{
|
|
10
|
+
w:192,
|
|
11
|
+
h:192,
|
|
12
|
+
fm:'webp',
|
|
13
|
+
fit:'fill'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return new Response(JSON.stringify({
|
|
17
|
+
"short_name": siteinfo.site_uri,
|
|
18
|
+
"name": siteinfo.site_name,
|
|
19
|
+
"icons": [
|
|
20
|
+
{
|
|
21
|
+
"src": icon1,
|
|
22
|
+
"type": "image/webp",
|
|
23
|
+
"sizes": "192x192",
|
|
24
|
+
"purpose": "any maskable"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"start_url": site,
|
|
28
|
+
"background_color": siteinfo.theme_color,
|
|
29
|
+
"theme_color": siteinfo.theme_color
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
import config from "virtual:jeawin-runtime-config/config";
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
|
|
5
|
+
export const GET:APIRoute = async ({site, locals}) => {
|
|
6
|
+
|
|
7
|
+
let sitemaptxt = ``;
|
|
8
|
+
const resdata = await locals.jeawinapi.get_all_uri();
|
|
9
|
+
for (const obj of resdata) {
|
|
10
|
+
sitemaptxt+= `${site+obj.url+(obj.url ? (_.get(config, 'build.format', '') === 'file' ? '.html' : '/') : '')}\n`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
return new Response(sitemaptxt);
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
import config from "virtual:jeawin-runtime-config/config";
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
|
|
5
|
+
export const GET:APIRoute = async ({site, locals}) => {
|
|
6
|
+
|
|
7
|
+
let sitemapxml = `<?xml version="1.0" encoding="UTF-8" ?>
|
|
8
|
+
<?xml-stylesheet type="text/xsl" href="/sitemap.xsl" ?>
|
|
9
|
+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
10
|
+
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
|
|
11
|
+
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-image/1.1 http://www.google.com/schemas/sitemap-image/1.1/sitemap-image.xsd"
|
|
12
|
+
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`;
|
|
13
|
+
const resdata = await locals.jeawinapi.get_all_uri();
|
|
14
|
+
for (const obj of resdata) {
|
|
15
|
+
sitemapxml+= `<url>
|
|
16
|
+
<loc>${site+obj.url+(obj.url ? (_.get(config, 'build.format', '') === 'file' ? '.html' : '/') : '')}</loc>
|
|
17
|
+
<lastmod>${obj.lastmod}</lastmod>
|
|
18
|
+
</url>`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
sitemapxml += `</urlset>`;
|
|
22
|
+
|
|
23
|
+
return new Response(sitemapxml, {
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/xml"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type {APIRoute} from "astro";
|
|
2
|
+
|
|
3
|
+
export const GET:APIRoute = ({site}) => {
|
|
4
|
+
return new Response(`<?xml version="1.0" encoding="UTF-8"?>
|
|
5
|
+
<xsl:stylesheet version="2.0"
|
|
6
|
+
xmlns:html="http://www.w3.org/TR/REC-html40"
|
|
7
|
+
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
|
|
8
|
+
xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
9
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
10
|
+
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
|
|
11
|
+
<xsl:template match="/">
|
|
12
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
13
|
+
<head>
|
|
14
|
+
<title>XML Sitemap</title>
|
|
15
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
16
|
+
<style type="text/css">
|
|
17
|
+
body {
|
|
18
|
+
font-family: Helvetica, Arial, sans-serif;
|
|
19
|
+
font-size: 13px;
|
|
20
|
+
color: #8b949e;
|
|
21
|
+
background-color: #0d1117;
|
|
22
|
+
}
|
|
23
|
+
table {
|
|
24
|
+
border-collapse: collapse;
|
|
25
|
+
}
|
|
26
|
+
#kh8EJsc tbody tr:hover td {
|
|
27
|
+
background-color: #161b22;
|
|
28
|
+
}
|
|
29
|
+
#fsb8Sfx {
|
|
30
|
+
width: 950px;
|
|
31
|
+
}
|
|
32
|
+
h1 {
|
|
33
|
+
color: #f0f6fc;
|
|
34
|
+
}
|
|
35
|
+
a {
|
|
36
|
+
color: #58a6ff;
|
|
37
|
+
text-decoration: none;
|
|
38
|
+
}
|
|
39
|
+
a:hover {
|
|
40
|
+
text-decoration: underline;
|
|
41
|
+
}
|
|
42
|
+
td {
|
|
43
|
+
font-size:11px;
|
|
44
|
+
}
|
|
45
|
+
th {
|
|
46
|
+
text-align:left;
|
|
47
|
+
padding-right:30px;
|
|
48
|
+
font-size:11px;
|
|
49
|
+
}
|
|
50
|
+
tr {
|
|
51
|
+
border-bottom: 1px solid #21262d;
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
54
|
+
</head>
|
|
55
|
+
<body>
|
|
56
|
+
<div id="fsb8Sfx">
|
|
57
|
+
<h1>XML Sitemap</h1>
|
|
58
|
+
<xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) > 0">
|
|
59
|
+
<p>
|
|
60
|
+
This XML Sitemap Index file contains <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/> sitemaps.
|
|
61
|
+
</p>
|
|
62
|
+
<table id="kh8EJsc" cellpadding="3">
|
|
63
|
+
<thead>
|
|
64
|
+
<tr>
|
|
65
|
+
<th width="75%">Sitemap</th>
|
|
66
|
+
<th width="25%">Last Modified</th>
|
|
67
|
+
</tr>
|
|
68
|
+
</thead>
|
|
69
|
+
<tbody>
|
|
70
|
+
<xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
|
|
71
|
+
<xsl:variable name="sitemapURL">
|
|
72
|
+
<xsl:value-of select="sitemap:loc"/>
|
|
73
|
+
</xsl:variable>
|
|
74
|
+
<tr>
|
|
75
|
+
<td>
|
|
76
|
+
<a href="{$sitemapURL}"><xsl:value-of select="sitemap:loc"/></a>
|
|
77
|
+
</td>
|
|
78
|
+
<td>
|
|
79
|
+
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)),concat(' ', substring(sitemap:lastmod,20,6)))"/>
|
|
80
|
+
</td>
|
|
81
|
+
</tr>
|
|
82
|
+
</xsl:for-each>
|
|
83
|
+
</tbody>
|
|
84
|
+
</table>
|
|
85
|
+
</xsl:if>
|
|
86
|
+
<xsl:if test="count(sitemap:sitemapindex/sitemap:sitemap) < 1">
|
|
87
|
+
<p>
|
|
88
|
+
This XML Sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.
|
|
89
|
+
</p>
|
|
90
|
+
<table id="kh8EJsc" cellpadding="3">
|
|
91
|
+
<thead>
|
|
92
|
+
<tr>
|
|
93
|
+
<th width="80%">URL</th>
|
|
94
|
+
<th width="5%">Images</th>
|
|
95
|
+
<th title="Last Modification Time" width="15%">Last Modified</th>
|
|
96
|
+
</tr>
|
|
97
|
+
</thead>
|
|
98
|
+
<tbody>
|
|
99
|
+
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
|
|
100
|
+
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
|
|
101
|
+
<xsl:for-each select="sitemap:urlset/sitemap:url">
|
|
102
|
+
<tr>
|
|
103
|
+
<td>
|
|
104
|
+
<xsl:variable name="itemURL">
|
|
105
|
+
<xsl:value-of select="sitemap:loc"/>
|
|
106
|
+
</xsl:variable>
|
|
107
|
+
<a href="{$itemURL}">
|
|
108
|
+
<xsl:value-of select="sitemap:loc"/>
|
|
109
|
+
</a>
|
|
110
|
+
</td>
|
|
111
|
+
<td>
|
|
112
|
+
<xsl:value-of select="count(image:image)"/>
|
|
113
|
+
</td>
|
|
114
|
+
<td>
|
|
115
|
+
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)),concat(' ', substring(sitemap:lastmod,20,6)))"/>
|
|
116
|
+
</td>
|
|
117
|
+
</tr>
|
|
118
|
+
</xsl:for-each>
|
|
119
|
+
</tbody>
|
|
120
|
+
</table>
|
|
121
|
+
</xsl:if>
|
|
122
|
+
</div>
|
|
123
|
+
</body>
|
|
124
|
+
</html>
|
|
125
|
+
</xsl:template>
|
|
126
|
+
</xsl:stylesheet>`,{
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "text/xsl"
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|