@@ -22,53 +22,121 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
SOFTWARE.
23
23
*/
24
24
25
+ const template = {
26
+ "title" : ( url ) => `Redirecting to ${ url } ...` ,
27
+ "description" : "Made with Just an Ultimate Site Tool"
28
+ }
25
29
const fs = require ( 'fs' ) ;
30
+ const compress = ( string ) => string . replaceAll ( `\n` , '' ) . replaceAll ( ' ' , '' ) ;
26
31
27
32
const config = JSON . parse ( fs . readFileSync ( 'just.config.json' , 'utf-8' ) ) ;
28
33
const redirectConfig = config . redirect_config ;
29
34
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 ;
32
52
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 } >
36
60
<head>
37
61
<meta charset="UTF-8">
38
62
<meta name="viewport" content="width=device-width, initial-scale=1.0">
39
63
<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 } "/>
41
73
</head>
42
74
<body>
43
75
<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>
44
80
<script src="/_just/${ page } .js"></script>
45
81
</body>
46
82
</html>
47
- ` ;
83
+ ` ) . replace ( '<just/>' , '<!DOCTYPE html>\n' ) ;
48
84
49
85
fs . writeFileSync ( `deploy/${ page } .html` , htmlContent ) ;
50
86
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 } ';` ;
65
88
fs . writeFileSync ( `deploy/_just/${ page } .js` , jsContent ) ;
66
89
} ;
67
90
68
- generatePage ( redirectConfig . url , redirectConfig . title ) ;
91
+ generatePage ( redirectConfig . url , redirectConfig . params ) ;
69
92
70
93
if ( 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_ ) ;
73
96
} ) ;
74
97
}
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