@@ -26,11 +26,14 @@ SOFTWARE.
2626
2727const template = {
2828 "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"
3032}
3133const fs = require ( 'fs' ) ;
3234const path = require ( 'path' ) ;
3335const 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 ;
3437
3538const config = JSON . parse ( fs . readFileSync ( 'just.config.json' , 'utf-8' ) ) ;
3639const redirectConfig = config . redirect_config ;
@@ -39,55 +42,101 @@ const cssContent = compress(fs.readFileSync(path.join(__dirname, 'style.css'), '
3942fs . writeFileSync ( `deploy/_just/style.css` , cssContent ) ;
4043
4144const 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 ) ;
4358 const tempDescription = template . description ;
44- const tempTwitterCard = "summary_large_image" ;
59+ const tempViewport = template . viewport ;
4560
4661 const title = params ? params . title || tempTitle : tempTitle ;
4762 const description = params ? params . description || tempDescription : tempDescription ;
4863 const metaKeywords = params ? params . keywords || undefined : undefined ;
4964 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 ;
5072
5173 const ogTitle = params && params . og ? params . og . title || title : title ;
5274 const ogDescription = params && params . og ? params . og . description || description : description ;
5375
54- const twitterCard = params && params . twitter ? params . twitter . card || tempTwitterCard : tempTwitterCard ;
76+ const twitterCard = params && params . twitter ? params . twitter . card || template . twitter : template . twitter ;
5577
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" ;
5784 const keywords = metaKeywords ? `<meta name="keywords" content="${ metaKeywords } "/>` : '' ;
5885 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+ }
59109
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 } >
63113 <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 } ">
66116 <title>${ title } </title>
67117 <link rel="stylesheet" href="/_just/style.css">
68118 <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 ( ) }
76126 </head>
77127 <body>
78128 <h1>${ title } </h1>
79129 <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>
82132 </div>
83133 <script src="/_just/${ page } .js"></script>
84134 </body>
85- </html>
86- ` ) . replace ( '<just/>' , '<!DOCTYPE html>\n' ) ;
135+ </html>` ) ;
87136
88137 fs . writeFileSync ( `deploy/${ page } .html` , htmlContent ) ;
89138
90- const jsContent = `window.location.href='${ url } ';` ;
139+ const jsContent = `window.location.href='${ URL } ';` ;
91140 fs . writeFileSync ( `deploy/_just/${ page } .js` , jsContent ) ;
92141} ;
93142
0 commit comments