2222
2323# Modify Deployment
2424
25+ # Checks
2526if [ -d " deploy/_just" ]; then
2627 echo " Error: Your website has a _just directory in the root. Please remove it to proceed." >&2
2728 exit 1
2829fi
30+ if [ -d " _just/dangerously-insert-files/_just" ]; then
31+ echo " Error: Inserting files in _just directory is not allowed." >&2
32+ exit 1
33+ fi
34+ if [ -d " _just/dangerously-insert-files/_next" ]; then
35+ echo " Error: Inserting files in _next directory is not allowed." >&2
36+ exit 1
37+ fi
2938
3039mkdir -p deploy/_just/
3140echo -e " \n----------------\n\n_just Chunks:\n"
3241
42+ generate_strings () {
43+ local count=$1
44+ local length=$2
45+ local chars=" qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890-_"
46+ for (( i= 0 ; i< count; i++ )) ; do
47+ local random_string=" "
48+ for (( j= 0 ; j< length; j++ )) ; do
49+ random_string+=" ${chars: RANDOM% 32: 1} "
50+ done
51+ echo " $random_string "
52+ done
53+ }
54+
3355# Merging logic
34- merged_file=" deploy/_just/merged.js"
56+ mkdir -p _just/dangerously-insert-files/_just/
57+ merged_data=($( generate_strings 1 16) )
58+ merged_name=${merged_data[0]}
59+ mkdir -p _just/dangerously-insert-files/_just/$merged_name /
60+ merged_file=" _just/dangerously-insert-files/_just/$merged_name /merged.js"
3561> " $merged_file "
3662for file in _just/js/* ; do
3763 file_size=$( stat -c%s " $file " )
@@ -41,8 +67,6 @@ for file in _just/js/*; do
4167 fi
4268done
4369
44- echo " t1"
45-
4670# Check if merged file is less than 128KB
4771while [[ $( stat -c%s " $merged_file " ) -lt 131072 ]]; do
4872 largest_file=$( ls -S _just/js/* | head -n 1) # Get the largest original file
@@ -56,8 +80,6 @@ while [[ $(stat -c%s "$merged_file") -lt 131072 ]]; do
5680 fi
5781done
5882
59- echo " t2"
60-
6183# Move unmerged files to _just/js/
6284for file in _just/js/* ; do
6385 first_line=$( head -n 1 " $file " )
@@ -69,25 +91,41 @@ for file in _just/js/*; do
6991 fi
7092done
7193
72- echo " t3 "
94+ mkdir -p _just_data/_just/
7395
7496# Move js files to deploy/_just/
97+ TOTAL_FILES_JS=0
98+ for file in _just/js/* ; do
99+ TOTAL_FILES_JS=$(( TOTAL_FILES_JS + 1 ))
100+ done
101+ random_strings_js=($( generate_strings $TOTAL_FILES_JS 14) )
75102FILE_ID=1
76103for file in _just/js/* ; do
77104 first_line=$( head -n 1 " $file " )
78105 if [[ $first_line == " // _just ignore" * ]]; then
79106 continue
80107 fi
81- cp " $file " " deploy/_just/${FILE_ID} .js"
82- echo " _just/${FILE_ID} .js"
108+ FILE_ID_M1=$(( FILE_ID - 1 ))
109+ FILE_NAME=${random_strings_js[$FILE_ID_M1]}
110+ cp " $file " " deploy/_just/${FILE_NAME}${FILE_ID} .js"
111+ cp " $file " " _just_data/_just/${FILE_NAME}${FILE_ID} .js"
112+ echo " _just/${FILE_NAME}${FILE_ID} .js"
83113 FILE_ID=$(( FILE_ID + 1 ))
84114done
85115
86116# Move css files to deploy/_just/
117+ TOTAL_FILES_CSS=0
118+ for file in _just/style/* ; do
119+ TOTAL_FILES_CSS=$(( TOTAL_FILES_CSS + 1 ))
120+ done
121+ random_strings_css=($( generate_strings $TOTAL_FILES_CSS 14) )
87122FILE_ID=1
88123for file in _just/style/* ; do
89- cp " $file " " deploy/_just/${FILE_ID} .css"
90- echo " _just/${FILE_ID} .css"
124+ FILE_ID_M1=$(( FILE_ID - 1 ))
125+ FILE_NAME=${random_strings_css[$FILE_ID_M1]}
126+ cp " $file " " deploy/_just/${FILE_NAME}${FILE_ID} .css"
127+ cp " $file " " _just_data/_just/${FILE_NAME}${FILE_ID} .css"
128+ echo " _just/${FILE_NAME}${FILE_ID} .css"
91129 FILE_ID=$(( FILE_ID + 1 ))
92130done
93131
@@ -99,12 +137,15 @@ echo -e "\n----------------\n\nDangerously Inserted Files:\n"
99137find _just/dangerously-insert-files/ -type f | while read -r file; do
100138 relative_path=" ${file# _just/ dangerously-insert-files/ } "
101139 target_dir=" deploy/$( dirname " $relative_path " ) "
140+ target_dir2=" _just_data/$( dirname " $relative_path " ) "
102141 mkdir -p " $target_dir "
142+ mkdir -p " $target_dir2 "
103143 if [ -f " $target_dir /$( basename " $file " ) " ]; then
104144 echo " Warning: Failed to insert file \" $target_dir /$( basename " $file " ) \" ."
105145 fi
106146 if [ ! -f " $target_dir /$( basename " $file " ) " ]; then
107147 cp " $file " " $target_dir /$( basename " $file " ) "
148+ cp " $file " " $target_dir2 /$( basename " $file " ) "
108149 echo " $target_dir /$( basename " $file " ) "
109150 fi
110151done
0 commit comments