Skip to content

Commit c955a77

Browse files
Updates
1 parent b800133 commit c955a77

File tree

8 files changed

+149
-42
lines changed

8 files changed

+149
-42
lines changed

src/modules/errmsg.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@
2222

2323
#!/bin/bash
2424
ERRORS_FILE="$GITHUB_ACTION_PATH/data/codes.json"
25+
ERROR_PREFIX="Just an Ultimate Site Tool"
2526

2627
ErrorMessage() {
2728
local ERROR_CODE=$2
2829
local ERROR_MESSAGE=${3:-$(jq -r ".[\"$1\"][] | select(.code==\"$ERROR_CODE\") | .message" "$ERRORS_FILE")}
2930
local ERROR_LINK=$(jq -r ".[\"$1\"][] | select(.code==\"$ERROR_CODE\") | .link" "$ERRORS_FILE")
30-
echo -e "\n\n\n\nError $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK"
31+
local ERROR_TYPE="Error"
32+
if [[ $ERROR_CODE == 02* ]]; then
33+
ERROR_TYPE="Warning"
34+
fi
35+
echo -e "\n\n\n\n$ERROR_PREFIX: $ERROR_TYPE $ERROR_CODE: $ERROR_MESSAGE $ERROR_LINK\n\n\n\n"
3136
}
3237

33-
export -f ErrorMessage
38+
export -f ErrorMessage

src/modules/string.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ generate_strings() {
3434
done
3535
}
3636

37-
export -f generate_strings
37+
export -f generate_strings

src/postprocessor/create_api_endpoints.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222

2323
# API Endpoints
2424

25+
source $GITHUB_ACTION_PATH/src/modules/errmsg.sh
26+
2527
if [ -d "deploy/api" ]; then
26-
echo "Error: Your website have api directory in the root. Please remove it to proceed." >&2
27-
exit 1
28+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/create_api_endpoints.sh" "0102"))
29+
echo $ERROR_MESSAGE && exit 1
2830
fi
29-
3031
mkdir -p deploy/api/
3132

3233
BUILD_ID=$(cat .next/BUILD_ID)

src/postprocessor/modify_deployment.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@
2222

2323
# Modify Deployment
2424

25+
source $GITHUB_ACTION_PATH/src/modules/errmsg.sh
26+
if [ -d "deploy/_just" ]; then
27+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/modify_deployment.sh" "0103"))
28+
echo $ERROR_MESSAGE && exit 1
29+
fi
30+
mkdir -p deploy/_just/
31+
2532
if [ -d "_just/dangerously-insert-files/_just" ]; then
26-
echo "Error: Inserting files in _just directory is not allowed." >&2
27-
exit 1
33+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/modify_deployment.sh" "0104"))
34+
echo $ERROR_MESSAGE && exit 1
2835
fi
2936
if [ -d "_just/dangerously-insert-files/_next" ]; then
30-
echo "Error: Inserting files in _next directory is not allowed." >&2
31-
exit 1
37+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/modify_deployment.sh" "0105"))
38+
echo $ERROR_MESSAGE && exit 1
3239
fi
3340

3441
echo -e "\n----------------\n\n_just Chunks:\n"

src/postprocessor/override_deployment.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
# Override Deployment
2424

25+
source $GITHUB_ACTION_PATH/src/modules/errmsg.sh
26+
2527
find deploy -type f -name "*.html" | while read -r html_file; do
2628
for js_file in deploy/_just/*.js; do
2729
first_line=$(head -n 1 "$js_file")
@@ -42,7 +44,8 @@ find deploy -type f -name "*.html" | while read -r html_file; do
4244
done
4345

4446
if [ -f "deploy/404.html" ]; then
45-
echo "Warning: Your website already has a 404.html file, _just/404.html won't be inserted."
47+
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/override_deployment.sh" "0202"))
48+
echo $ERROR_MESSAGE
4649
fi
4750
if [ ! -f "deploy/404.html" ]; then
4851
cp _just/404.html deploy/404.html

src/redirect/index.js

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,121 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
2323
*/
2424

25+
const template = {
26+
"title": (url) => `Redirecting to ${url}...`,
27+
"description": "Made with Just an Ultimate Site Tool"
28+
}
2529
const fs = require('fs');
30+
const compress = (string) => string.replaceAll(`\n`,'').replaceAll(' ','');
2631

2732
const config = JSON.parse(fs.readFileSync('just.config.json', 'utf-8'));
2833
const 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

7093
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_);
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+
*/

src/redirect/style.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap');
2+
3+
html {
4+
background-color: #111111;
5+
padding: 10px;
6+
display: block;
7+
}
8+
body {
9+
width: calc( 100% - 44px );
10+
height: calc( 100% - 44px );
11+
position: fixed;
12+
margin: 0px;
13+
padding: 10px;
14+
display: block;
15+
border-radius: 15px;
16+
background-color: #222222;
17+
background-image: linear-gradient(83deg, #353535, #232323);
18+
filter: drop-shadow(2px 4px 6px #000000);
19+
border-width: 2px;
20+
border-style: solid;
21+
border-color: #5f5f5f;
22+
-webkit-filter: drop-shadow(2px 4px 6px #000000);
23+
}
24+
h1 {
25+
display: block;
26+
font-size: 20px;
27+
margin: 0px;
28+
color: #dddddd;
29+
text-align: center;
30+
}

src/run.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ fi
7272
mkdir -p deploy
7373
mkdir -p _just_data
7474

75-
if [ -d "deploy/_just" ]; then
76-
local ERROR_MESSAGE=($(ErrorMessage "postprocessor/modify_deployment.sh" "0103"))
77-
echo $ERROR_MESSAGE && exit 1
78-
fi
79-
mkdir -p deploy/_just/
80-
8175
if [ "$TYPE" == "postprocessor" ]; then
8276
set -e
8377
postprocessor_checks=$(bash $GITHUB_ACTION_PATH/src/postprocessor/checks.sh 2>&1) || {
@@ -100,4 +94,3 @@ elif [ "$TYPE" == "redirect" ]; then
10094
sudo apt install -y nodejs npm
10195
node $GITHUB_ACTION_PATH/src/redirect/index.js
10296
fi
103-

0 commit comments

Comments
 (0)