@@ -22,53 +22,121 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222SOFTWARE.
2323*/
2424
25+ const template = {
26+ "title" : ( url ) => `Redirecting to ${ url } ...` ,
27+ "description" : "Made with Just an Ultimate Site Tool"
28+ }
2529const fs = require ( 'fs' ) ;
30+ const compress = ( string ) => string . replaceAll ( `\n` , '' ) . replaceAll ( ' ' , '' ) ;
2631
2732const config = JSON . parse ( fs . readFileSync ( 'just.config.json' , 'utf-8' ) ) ;
2833const redirectConfig = config . redirect_config ;
2934
30- const generatePage = ( url , title , path_ ) => {
31- const page = path_ || "index"
35+ const cssContent = compress ( fs . readFileSync ( './style.css' , 'utf-8' ) ) ;
36+ fs . writeFileSync ( `deploy/_just/style.css` , cssContent ) ;
37+
38+ const generatePage = ( url , params , path_ ) => {
39+ const tempTitle = template . title ( url ) ;
40+ const tempDescription = template . description ;
41+ const tempTwitterCard = "summary_large_image" ;
42+
43+ const title = params ? params . title || tempTitle : tempTitle ;
44+ const description = params ? params . description || tempDescription : tempDescription ;
45+ const metaKeywords = params ? params . keywords || undefined : undefined ;
46+ const lang = params ? params . htmlLang || undefined : undefined ;
47+
48+ const ogTitle = params && params . og ? params . og . title || title : title ;
49+ const ogDescription = params && params . og ? params . og . description || description : description ;
50+
51+ const twitterCard = params && params . twitter ? params . twitter . card || tempTwitterCard : tempTwitterCard ;
3252
33- const htmlContent = `
34- <!DOCTYPE html>
35- <html lang="en">
53+ const page = path_ || "index" ;
54+ const keywords = metaKeywords ? `<meta name="keywords" content="${ metaKeywords } "/>` : '' ;
55+ const htmlLang = lang ? ` lang="${ `${ lang } ` . toLowerCase ( ) } "` : '' ;
56+
57+ const linkElement = `<a href="${ url } " target="_self">` ;
58+ const htmlContent = compress ( `<just/>
59+ <html${ htmlLang } >
3660 <head>
3761 <meta charset="UTF-8">
3862 <meta name="viewport" content="width=device-width, initial-scale=1.0">
3963 <title>${ title } </title>
40- <link rel="stylesheet" href="/_just/${ page } .css">
64+ <link rel="stylesheet" href="/_just/style.css">
65+ <meta name="description" content="${ description } "/>${ keywords }
66+ <meta property="og:title" content="${ title } "/>
67+ <meta property="og:description" content="${ description } "/>
68+ <meta property="og:type" content="website"/>
69+ <meta property="twitter:card" content="${ twitterCard } "/>
70+ <meta property="og:title" content="${ ogTitle } "/>
71+ <meta property="og:description" content="${ ogDescription } "/>
72+ <meta property="og:url" content="${ url } "/>
4173 </head>
4274 <body>
4375 <h1>${ title } </h1>
76+ <div>
77+ <span class="r">Redirecting...<br><small>to ${ linkElement } ${ url } </a></small></span>
78+ <span class="d">Didn't get redirected? ${ linkElement } Click here!</a></span>
79+ </div>
4480 <script src="/_just/${ page } .js"></script>
4581 </body>
4682 </html>
47- ` ;
83+ ` ) . replace ( '<just/>' , '<!DOCTYPE html>\n' ) ;
4884
4985 fs . writeFileSync ( `deploy/${ page } .html` , htmlContent ) ;
5086
51- const cssContent = `
52- body {
53- font-family: Arial, sans-serif;
54- text-align: center;
55- }
56- ` ;
57-
58- fs . writeFileSync ( `deploy/_just/${ page } .css` , cssContent ) ;
59-
60- const jsContent = `
61- console.log('Redirecting to ${ url } ');
62- window.location.href = '${ url } ';
63- ` ;
64-
87+ const jsContent = `window.location.href='${ url } ';` ;
6588 fs . writeFileSync ( `deploy/_just/${ page } .js` , jsContent ) ;
6689} ;
6790
68- generatePage ( redirectConfig . url , redirectConfig . title ) ;
91+ generatePage ( redirectConfig . url , redirectConfig . params ) ;
6992
7093if ( redirectConfig . paths ) {
71- redirectConfig . paths . forEach ( ( { path_, url, title } ) => {
72- generatePage ( url , title , path_ ) ;
94+ redirectConfig . paths . forEach ( ( { path_, url, params } ) => {
95+ generatePage ( url , params , path_ ) ;
7396 } ) ;
7497}
98+
99+ /*
100+
101+ EXAMPLE just.config.js FILE for redirect(s):
102+
103+ module.exports = {
104+ type: "redirect",
105+ redirect_config: {
106+ url: "https://justdeveloper.is-a.dev/",
107+ params: {
108+ title: "JustDeveloper",
109+ description: "the one who created this shi-",
110+ keywords: "Just, an, Ultimate, Site, Tool",
111+ htmlLang: "en",
112+ og: {
113+ title: "Redirect",
114+ description: "Hello, World!"
115+ },
116+ twitter: {
117+ card: "summary_large_image"
118+ }
119+ },
120+ paths: [
121+ {
122+ path_: "github",
123+ url: "https://github.com/JustDeveloper1",
124+ params: {
125+ title: "JustDeveloper",
126+ description: "GitHub Profile",
127+ keywords: "Just, Developer",
128+ htmlLang: "en",
129+ og: {
130+ title: "Redirect2",
131+ description: "Hello, GitHub!"
132+ },
133+ twitter: {
134+ card: "summary_large_image"
135+ }
136+ }
137+ }
138+ ]
139+ }
140+ }
141+
142+ */
0 commit comments