@@ -26,11 +26,14 @@ SOFTWARE.
26
26
27
27
const template = {
28
28
"title" : ( url ) => `Redirecting to ${ url } ...` ,
29
- "description" : "Made with Just an Ultimate Site Tool"
29
+ "description" : "Made with Just an Ultimate Site Tool" ,
30
+ "viewport" : "width=device-width, initial-scale=1.0" ,
31
+ "twitter" : "summary_large_image"
30
32
}
31
33
const fs = require ( 'fs' ) ;
32
34
const path = require ( 'path' ) ;
33
35
const compress = ( string ) => string . replaceAll ( `\n` , '' ) . replaceAll ( ' ' , '' ) ;
36
+ const filter = ( input ) => input ? input . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, ( char ) => `&#${ char . charCodeAt ( 0 ) } ;` ) : undefined ;
34
37
35
38
const config = JSON . parse ( fs . readFileSync ( 'just.config.json' , 'utf-8' ) ) ;
36
39
const redirectConfig = config . redirect_config ;
@@ -39,55 +42,101 @@ const cssContent = compress(fs.readFileSync(path.join(__dirname, 'style.css'), '
39
42
fs . writeFileSync ( `deploy/_just/style.css` , cssContent ) ;
40
43
41
44
const generatePage = ( url , params , path_ ) => {
42
- const tempTitle = template . title ( url ) ;
45
+ const URL = compress ( `${ url } ` ) ;
46
+ const PATH = ( path_ ) => {
47
+ let output = compress ( `${ path_ } ` ) . toLowerCase ( ) ;
48
+ if ( output . startsWith ( '/' ) ) {
49
+ output = output . slice ( 1 ) ;
50
+ }
51
+ if ( output . endsWith ( '/' ) ) {
52
+ output += 'index' ;
53
+ }
54
+ return output ;
55
+ }
56
+
57
+ const tempTitle = template . title ( URL ) ;
43
58
const tempDescription = template . description ;
44
- const tempTwitterCard = "summary_large_image" ;
59
+ const tempViewport = template . viewport ;
45
60
46
61
const title = params ? params . title || tempTitle : tempTitle ;
47
62
const description = params ? params . description || tempDescription : tempDescription ;
48
63
const metaKeywords = params ? params . keywords || undefined : undefined ;
49
64
const lang = params ? params . htmlLang || undefined : undefined ;
65
+ const robots = params ? params . robots || undefined : undefined ;
66
+ const charset = params ? params . charset || "UTF-8" : "UTF-8" ;
67
+ const viewport = params ? params . viewport || tempViewport : tempViewport ;
68
+
69
+ const text1 = params && params . content ? filter ( params . content . text1 ) || undefined : undefined ;
70
+ const text2 = params && params . content ? filter ( params . content . text2 ) || undefined : undefined ;
71
+ const text3 = params && params . content ? filter ( params . content . text3 ) || undefined : undefined ;
50
72
51
73
const ogTitle = params && params . og ? params . og . title || title : title ;
52
74
const ogDescription = params && params . og ? params . og . description || description : description ;
53
75
54
- const twitterCard = params && params . twitter ? params . twitter . card || tempTwitterCard : tempTwitterCard ;
76
+ const twitterCard = params && params . twitter ? params . twitter . card || template . twitter : template . twitter ;
55
77
56
- const page = path_ || "index" ;
78
+ const yandexVerification = params ? params . yandex || undefined : undefined ;
79
+
80
+ const googleAnalytics = params ? params . googleAnalytics || undefined : undefined ;
81
+ const googleVerification = params ? params . google || undefined : undefined ;
82
+
83
+ const page = path_ ? PATH ( ) : "index" ;
57
84
const keywords = metaKeywords ? `<meta name="keywords" content="${ metaKeywords } "/>` : '' ;
58
85
const htmlLang = lang ? ` lang="${ `${ lang } ` . toLowerCase ( ) } "` : '' ;
86
+ const optionalstuff = ( ) => {
87
+ let output = '' ;
88
+ if ( yandexVerification ) {
89
+ output += `\n<meta name="yandex-verification" content="${ yandexVerification } "/>` ;
90
+ }
91
+ if ( googleVerification ) {
92
+ output += `\n<meta name="google-site-verification" content="${ googleVerification } " />` ;
93
+ }
94
+ if ( googleAnalytics ) {
95
+ output += `\n<script async src="https://www.googletagmanager.com/gtag/js?id=${ googleAnalytics } "></script>
96
+ <script>
97
+ window.dataLayer = window.dataLayer || [];
98
+ function gtag() {
99
+ dataLayer.push(arguments);
100
+ }
101
+ gtag('js', new Date());
102
+ gtag('config', '${ googleAnalytics } ');
103
+ </script>`
104
+ }
105
+ if ( robots ) {
106
+ output += `\n<meta name="robots" content="${ robots } " />`
107
+ }
108
+ }
59
109
60
- const linkElement = `<a href="${ url } " target="_self">` ;
61
- const htmlContent = compress ( `<just/>
62
- <html${ htmlLang } >
110
+ const link = `<a href="${ URL } " target="_self">` ;
111
+ const meta = '<meta property=' ;
112
+ const htmlContent = '<!DOCTYPE html>\n' + compress ( ` <html${ htmlLang } >
63
113
<head>
64
- <meta charset="UTF-8 ">
65
- <meta name="viewport" content="width=device-width, initial-scale=1.0 ">
114
+ <meta charset="${ charset } ">
115
+ <meta name="viewport" content="${ viewport } ">
66
116
<title>${ title } </title>
67
117
<link rel="stylesheet" href="/_just/style.css">
68
118
<meta name="description" content="${ description } "/>${ keywords }
69
- < meta property= "og:title" content="${ title } "/>
70
- < meta property= "og:description" content="${ description } "/>
71
- < meta property= "og:type" content="website"/>
72
- < meta property= "twitter:card" content="${ twitterCard } "/>
73
- < meta property= "og:title" content="${ ogTitle } "/>
74
- < meta property= "og:description" content="${ ogDescription } "/>
75
- < meta property= "og:url" content="${ url } "/>
119
+ ${ meta } "og:title" content="${ title } "/>
120
+ ${ meta } "og:description" content="${ description } "/>
121
+ ${ meta } "og:type" content="website"/>
122
+ ${ meta } "twitter:card" content="${ twitterCard } "/>
123
+ ${ meta } "og:title" content="${ ogTitle } "/>
124
+ ${ meta } "og:description" content="${ ogDescription } "/>
125
+ ${ meta } "og:url" content="${ URL } "/>${ optionalstuff ( ) }
76
126
</head>
77
127
<body>
78
128
<h1>${ title } </h1>
79
129
<div>
80
- <span class="r">Redirecting...<br><small>to ${ linkElement } ${ url } </a></small></span>
81
- <span class="d">Didn't get redirected? ${ linkElement } Click here!</a></span>
130
+ <span class="r">${ text1 || ` Redirecting...<br><small>to ${ link } ${ URL } </a></small>` } </span>
131
+ <span class="d">${ text2 || " Didn't get redirected?" } ${ link } ${ text3 || ' Click here!' } </a></span>
82
132
</div>
83
133
<script src="/_just/${ page } .js"></script>
84
134
</body>
85
- </html>
86
- ` ) . replace ( '<just/>' , '<!DOCTYPE html>\n' ) ;
135
+ </html>` ) ;
87
136
88
137
fs . writeFileSync ( `deploy/${ page } .html` , htmlContent ) ;
89
138
90
- const jsContent = `window.location.href='${ url } ';` ;
139
+ const jsContent = `window.location.href='${ URL } ';` ;
91
140
fs . writeFileSync ( `deploy/_just/${ page } .js` , jsContent ) ;
92
141
} ;
93
142
0 commit comments