~npisanti/npisantidotcomssg

ref: 88cdde99b2328f6ba743af66967b9d063f55c83f npisantidotcomssg/build.sh -rwxr-xr-x 17.6 KiB
88cdde99Nicola Pisanti finished fish script 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
#!/bin/bash

# --------------------------------------------------------------------
# ---------------- FUNCTIONS -----------------------------------------
# --------------------------------------------------------------------
build_navigation_footer(){
    # generate navigation pages 
    navfold="$1"
    numpage="$2"
    archive_enable="$3"

    #echo "generating navigation bars..."
    for ((i=1;i<=numpage;i++)); do
        navigation=""
        
        if [ ! -z "$archive_enable" ]; then 
            navigation="$navigation<a href=\"archive.html\">all</a> "        
        fi

        for ((k=1;k<=numpage;k++)); do
            if (("$k" == "$i")); then 
                navigation="$navigation<a href=\"page$k.html\">[$k]</a> "
            else
                navigation="$navigation<a href=\"page$k.html\">$k</a> "
            fi
        done

        navigation="$navigation\&nbsp;\&nbsp;"
        
        if [ "$i" -ne "1" ]; then 
            prev=$(( $i - 1 ))
            navigation="$navigation<a href=\"page$prev.html\">prev</a> "
        fi
        if [ "$i" -ne "$numpage" ]; then 
            next=$(( $i + 1 ))
            navigation="$navigation<a href=\"page$next.html\">next</a> "
        fi
        
        sed -i -e "s|NAVIGATION_PLACEHOLDER_TOKEN|$navigation|g" "$navfold/page$i.html"
    done
    #echo "...done"    
}

add_og_image(){
    
    filesource="$1"
    filedestination="$2"
    
    POST_OG_THUMB=`cat $filesource | grep og_thumb=`
    
    if [ ! -z "$POST_OG_THUMB" -a "$POST_OG_THUMB" != " " ]; then 
        OG_THUMBFILE=$(echo $POST_OG_THUMB | cut -d '=' -f2)
        echo "    <meta property=\"og:image\" content=\"http://npisanti.com/data/$OG_THUMBFILE\" />" >> "$filedestination"            
    else
        echo "    <meta property=\"og:image\" content=\"http://npisanti.com/data/$GENERAL_THUMB\" />" >> "$filedestination"
    fi
}


# --------------------------------------------------------------------
# ---------------- SCRIPT --------------------------------------------
# --------------------------------------------------------------------

GENERAL_THUMB="avatars/avatar_og.png"
MASTERINDEX_THUMB="avatars/avatar_og.png"
HTMLDEST=/home/$USER/htdocs/npisantidotcomssg/html_output

THUMBSIZE=80
POSTPERPAGE=6
RSSMAXPOSTS=6

cd ~/htdocs/npisantidotcomssg
mkdir -p $HTMLDEST 
rm -rf $HTMLDEST/journal
rm -rf $HTMLDEST/main
rm -rf $HTMLDEST/posts

echo "cleaning folders..."
for d in input/journal/*/ ; do
    dirname=$(echo $d | cut -d '/' -f3)
    rm -rf "$HTMLDEST/$dirname"
done

rm $HTMLDEST/*

mkdir -p $HTMLDEST/main
mkdir -p $HTMLDEST/posts

for d in input/journal/*/ ; do
    dirname=$(echo $d | cut -d '/' -f3)
    mkdir -p "$HTMLDEST/$dirname"
done

cp input/base/style.css $HTMLDEST/style.css


# makes the pages page -----------------------------------------------
echo "<!DOCTYPE html>" >> $HTMLDEST/more.html
echo "<html>" >> $HTMLDEST/more.html
echo "<head>" >> $HTMLDEST/more.html
echo "<meta charset=\"utf-8\"/>" >> $HTMLDEST/more.html
echo "<title>npisanti.com</title>" >> $HTMLDEST/more.html
cat input/base/head.html >> $HTMLDEST/more.html
echo "<meta property=\"og:image\" content=\"http://npisanti.com/data/$GENERAL_THUMB\" />" >> $HTMLDEST/index.html
echo "<meta property=\"og:image:height\" content=\"230\" />" >> $HTMLDEST/more.html
echo "<meta property=\"og:image:width\" content=\"230\" />" >> $HTMLDEST/more.html
echo "</head>" >> $HTMLDEST/more.html
echo "<body>" >> $HTMLDEST/more.html
cat input/base/moreheader.html >> $HTMLDEST/more.html
cat input/base/more.html >> $HTMLDEST/more.html
echo "</body>" >> $HTMLDEST/more.html
echo "</html>" >> $HTMLDEST/more.html

# generate contact 
echo "processing contact file..."
echo "<!DOCTYPE html>" >> $HTMLDEST/contact.html
echo "<html>" >> $HTMLDEST/contact.html
echo "<head>" >> $HTMLDEST/contact.html
echo "<meta charset=\"utf-8\"/>" >> $HTMLDEST/contact.html
echo "<title>npisanti.com</title>" >> $HTMLDEST/contact.html
cat input/base/head.html >> $HTMLDEST/contact.html
echo "<meta property=\"og:image\" content=\"http://npisanti.com/data/$GENERAL_THUMB\" />" >> $HTMLDEST/contact.html
echo "</head>" >> $HTMLDEST/contact.html
echo "<body>" >> $HTMLDEST/contact.html
cat input/base/contact.html >> $HTMLDEST/contact.html
echo "</body></html>" >> $HTMLDEST/contact.html

# generate tcatnoc 
echo "processing tcatnoc file..."
echo "<!DOCTYPE html>" >> $HTMLDEST/tcatnoc.html
echo "<html>" >> $HTMLDEST/tcatnoc.html
echo "<head>" >> $HTMLDEST/tcatnoc.html
echo "<meta charset=\"utf-8\"/>" >> $HTMLDEST/tcatnoc.html
echo "<title>npisanti.com</title>" >> $HTMLDEST/tcatnoc.html
cat input/base/head.html >> $HTMLDEST/tcatnoc.html
# no og...
echo "</head>" >> $HTMLDEST/tcatnoc.html
echo "<body>" >> $HTMLDEST/tcatnoc.html
cat input/base/tcatnoc.html >> $HTMLDEST/tcatnoc.html
echo "</body></html>" >> $HTMLDEST/tcatnoc.html

echo "---- generating pages ----"
#generate pages

for f in input/pages/*.html; 
do
    filename=${f:12}
    title=${filename%".html"}

    #echo "processing $filename file..."
    echo "<!DOCTYPE html>" >> "$HTMLDEST/$filename"
    echo "<html>" >> "$HTMLDEST/$filename"
    
    echo "<head>" >> "$HTMLDEST/$filename"
    echo "<meta charset=\"utf-8\"/>" >> "$HTMLDEST/$filename"
    echo "<title>[ $title ]</title>" >> "$HTMLDEST/$filename"
    cat input/base/head.html >> "$HTMLDEST/$filename"
    
    add_og_image "input/pages/$filename" "$HTMLDEST/$filename"

    echo "</head>" >> "$HTMLDEST/$filename"
    
    echo "<body>" >> "$HTMLDEST/$filename"
    cat input/base/singlepageheader.html >> "$HTMLDEST/$filename"
    echo "<section>" >> "$HTMLDEST/$filename"
    cat input/pages/$filename >> "$HTMLDEST/$filename"
    echo "</section>" >> "$HTMLDEST/$filename"
    echo "</body></html>" >> "$HTMLDEST/$filename"
    
    sed -i -e "s|SITEROOTPATH/||g" "$HTMLDEST/$filename"
done

# --------------------------------------------------------------------
# ---------------- MAKES THE FEED ------------------------------------
# --------------------------------------------------------------------
echo "---- generating main feed ----"

post=0
page=0
monthcursor=13
yearcursor=1999
lastyear=2014
lastbuild="never"

#generate pages
inputlist=input/journal/feed.list
while read line
do
    if [ ! -z "$line" -a "$line" != " " ]; then 
    
        postpath="input/journal/$line"  
        filename=$(echo $line | cut -d '/' -f2)
        dirname=$(echo $line | cut -d '/' -f1)
        
        #filename=${f##*/}
        year=${filename:0:4}
        month=${filename:5:2}
        day=${filename:8:2}
        
        title=${filename:12}
        title=${title%".html"}
        title=${title//_/ }
        
        pagelink="posts/$filename"

        pagefolder="$HTMLDEST/main/"
        mkdir -p $pagefolder
        pagepath="$pagefolder/page$page.html"
        
        #generate corresponding page
        if (("$post" == 0)); then 
            page=$(( $page +1 ))
            echo "   - generating page $page"
            pagepath="$pagefolder/page$page.html"
            
            # generate head of page
            echo "<!DOCTYPE html>" >> "$pagepath"
            echo "<html>" >> "$pagepath"
            echo "<head>" >> "$pagepath"
            echo "<meta charset=\"utf-8\"/>" >> "$pagepath"
            echo "<title>npisanti.com</title>" >> "$pagepath"
            cat input/base/head.html >> "$pagepath"
            echo "<meta property=\"og:image\" content=\"http://npisanti.com/data/$GENERAL_THUMB\" />" >> "$pagepath"
            echo "</head>" >> "$pagepath"
            echo "<body>" >> "$pagepath"
            cat input/base/feedheader.html >> "$pagepath"
        fi 

        #echo "processing $postpath | post $post | page $page"
        
        # ------------ adds post to page ----------
        echo "<section>" >> "$pagepath"
        cat $postpath >> "$pagepath"

        echo "<br><br><div style=\"text-align:right\"><a href=\"../$pagelink\">$year/$month/$day</a> | posted in <a href=\"../$dirname/index.html\">$dirname</a></div>" >> "$pagepath"
        
        echo "</section>" >> "$pagepath"
        # -----------------------------------------

        post=$(( $post +1 ))
        if (("$post" == "$POSTPERPAGE")); then 
            post=0
            # generate tail of page 
            cat input/base/postpagefooter.html >> "$pagepath"
            echo "</body></html>" >> "$pagepath" 
        fi
    fi
done < "$inputlist"

# generate tail of page for last blog page
if (("$post" != 0)); then 
    cat input/base/postpagefooter.html >> "$pagepath"
    echo "</body></html>" >> "$pagepath" 
    sed -i -e "s|DATAPATH|$datapath|g" "$pagepath" 
fi

#echo "--- finished building main feed ---"

build_navigation_footer "$HTMLDEST/main" $page

#echo "copying and editing first page"
cp "$HTMLDEST/main/page1.html" "$HTMLDEST/main/index.html" 

echo "tweaking site index..."

cp "$HTMLDEST/main/page1.html" "$HTMLDEST/index.html" 
sed -i -e "s|href=\"../index.html\"|href=\"index.html\"|g" "$HTMLDEST/index.html" 
sed -i -e "s|../more|more|g" "$HTMLDEST/index.html" 
sed -i -e "s|../contact|contact|g" "$HTMLDEST/index.html" 
sed -i -e "s|../rss|rss|g" "$HTMLDEST/index.html" 
sed -i -e "s|href=\"page|href=\"main/page|g" "$HTMLDEST/index.html" 
sed -i -e "s|style=\"text-align:right\"><a href=\"../|style=\"text-align:right\"><a href=\"|g" "$HTMLDEST/index.html" 
sed -i -e "s|in <a href=\"|in <a href=\"main/|g" "$HTMLDEST/index.html" 

# -------------- generates individual journals ---------------

for d in input/journal/*/ ; do

    dirname=$(echo $d | cut -d '/' -f3)
    echo "---- generating $dirname's feed ----"

    post=0
    page=0
    monthcursor=13
    yearcursor=1999
    lastyear=2014
    lastbuild="never"
    
    for f in $(ls -1 "$d" | sort -r)
    do
        postpath="$f"  
        filename=${f##*/}
        year=${filename:0:4}
        month=${filename:5:2}
        day=${filename:8:2}
        
        title=${filename:12}
        title=${title%".html"}
        title=${title//_/ }    
        
        pagelink="posts/$filename"
        
        pagefolder="$HTMLDEST/$dirname/"
        mkdir -p $pagefolder
        pagepath="$pagefolder/page$page.html"
        
        #generate corresponding page
        if (("$post" == 0)); then 
            page=$(( $page +1 ))
            #echo "- generating page $page"
            pagepath="$pagefolder/page$page.html"
            
            # generate head of page
            echo "<!DOCTYPE html>" >> "$pagepath"
            echo "<html>" >> "$pagepath"
            echo "<head>" >> "$pagepath"
            echo "<meta charset=\"utf-8\"/>" >> "$pagepath"
            echo "<title>[ $dirname ]</title>" >> "$pagepath"
            cat input/base/head.html >> "$pagepath"
            echo "<meta property=\"og:image\" content=\"http://npisanti.com/data/$GENERAL_THUMB\" />" >> "$pagepath"
            echo "</head>" >> "$pagepath"
            echo "<body>" >> "$pagepath"
            cat input/base/channelheader.html >> "$pagepath"
        fi 

        #echo "processing $postpath | post $post | page $page"
        
        # ------------ adds post to page ----------
        echo "<section>" >> "$pagepath"
        cat "input/journal/$dirname/$postpath" >> "$pagepath"

        echo "<br><br><div style="text-align:right"><a href="../$pagelink">$year/$month/$day</a> | posted in <a href="../$dirname/index.html">$dirname</a></div>" >> "$pagepath"
        
        echo "</section>" >> "$pagepath"
        # -----------------------------------------

        post=$(( $post +1 ))
        if (("$post" == "$POSTPERPAGE")); then 
            post=0
            # generate tail of page 
            cat input/base/postpagefooter.html >> "$pagepath"
            echo "</body></html>" >> "$pagepath" 
        fi
    done 

    # generate tail of page for last blog page
    if (("$post" != 0)); then 
        cat input/base/postpagefooter.html >> "$pagepath"
        echo "</body></html>" >> "$pagepath" 
    fi

    build_navigation_footer "$HTMLDEST/$dirname" $page yes
    
    cp "$HTMLDEST/$dirname/page1.html" "$HTMLDEST/$dirname/index.html" 
done


# -------------- generates archives ---------------
for d in input/journal/*/ ; do
    dirname=$(echo $d | cut -d '/' -f3)
    echo "---- generating $dirname's archive and posts ----"

    post=0
    page=1
    monthcursor=13
    yearcursor=1999
    lastyear=2014
    lastbuild="never"
    
    # archive head ----------
    echo "<!DOCTYPE html>" >> "$HTMLDEST/$dirname/archive.html"
    echo "<html>" >> "$HTMLDEST/$dirname/archive.html"
    echo "<head>" >> "$HTMLDEST/$dirname/archive.html"
    echo "<meta charset=\"utf-8\"/>" >> "$HTMLDEST/$dirname/archive.html"
    echo "<title>npisanti.com</title>" >> "$HTMLDEST/$dirname/archive.html"
    cat input/base/head.html >> "$HTMLDEST/$dirname/archive.html"
    echo "<meta property=\"og:image\" content=\"http://npisanti.com/data/$GENERAL_THUMB\" />" >> "$HTMLDEST/$dirname/archive.html"
    echo "</head>" >> "$HTMLDEST/$dirname/archive.html"
    echo "<body>" >> "$HTMLDEST/$dirname/archive.html"
    cat input/base/channelheader.html >> "$HTMLDEST/$dirname/archive.html"
    echo "<section><br>" >> "$HTMLDEST/$dirname/archive.html"
    
    echo "$dirname's archive<br><br>" >> "$HTMLDEST/$dirname/archive.html"
    
    # --------------------------

    for f in $(ls -1 "$d" | sort -r)
    do
        postpath="$f"  
        filename=${f##*/}
        year=${filename:0:4}
        month=${filename:5:2}
        day=${filename:8:2}
        
        title=${filename:12}
        title=${title%".html"}
        title=${title//_/ }    
        
        postlink="posts/$filename"
    
        pagefolder="$HTMLDEST/$dirname/"
        
        echo "$year/$month/$day  <a href="../$postlink">$title</a><br>" >> "$HTMLDEST/$dirname/archive.html" 

        # ----------- generate individual page ----------------------
        echo "<!DOCTYPE html>" >> "$HTMLDEST/$postlink"
        echo "<html>" >> "$HTMLDEST/$postlink"
        echo "<head>" >> "$HTMLDEST/$postlink"
        echo "<meta charset=\"utf-8\"/>" >> "$HTMLDEST/$postlink"
        echo "<title>[ $title ]</title>" >> "$HTMLDEST/$postlink"
        cat input/base/head.html >> "$HTMLDEST/$postlink"
        
        add_og_image "input/journal/$dirname/$postpath" "$HTMLDEST/$postlink"
        echo "</head>" >> "$HTMLDEST/$postlink"
        echo "<body>" >> "$HTMLDEST/$postlink"
        cat input/base/channelheader.html >> "$HTMLDEST/$postlink"
        echo "<section>" >> "$HTMLDEST/$postlink"
        cat input/journal/$dirname/$postpath >> "$HTMLDEST/$postlink"

		echo "<br><br><div style="text-align:right"><a href="../$pagelink">$year/$month/$day</a> | posted in <a href="../$dirname/page$page.html">$dirname</a></div>" >> "$HTMLDEST/$postlink"

        echo "</section>" >> "$HTMLDEST/$postlink"
        echo "</body></html>" >> "$HTMLDEST/$postlink" 
        
        post=$(( $post +1 ))
        if (("$post" == "$POSTPERPAGE")); then 
            post=0
            page=$(( $page +1 ))
        fi
    done 
    
    # archive tail 
    echo "<br><br></section>" >> "$HTMLDEST/$dirname/archive.html"
    echo "</body></html>" >> "$HTMLDEST/$dirname/archive.html"
done

echo "---- building RSS ----"

cat input/base/rssbase.xml >> $HTMLDEST/rss.xml

inputlist=input/journal/rss.list
while read line
do
    if [ ! -z "$line" -a "$line" != " " ]; then 
    
        postpath="input/journal/$line"  
        filename=$(echo $line | cut -d '/' -f2)
        dirname=$(echo $line | cut -d '/' -f1)
        
        #filename=${f##*/}
        year=${filename:0:4}
        month=${filename:5:2}
        day=${filename:8:2}
        
        title=${filename:12}
        title=${title%".html"}
        title=${title//_/ }
        
        pagelink="posts/$filename"
        
        RFC822TIME=$(date --date=$month/$day/$year -R)

        echo -e "\t\t<item>" >> $HTMLDEST/rss.xml
        echo -e "\t\t\t<title>$title</title>" >> $HTMLDEST/rss.xml
        echo -e "\t\t\t<description><![CDATA[" >> $HTMLDEST/rss.xml
        cat $postpath >> $HTMLDEST/rss.xml
        echo -e "\t\t\t]]></description>" >> $HTMLDEST/rss.xml
        echo -e "\t\t\t<pubDate>$RFC822TIME</pubDate>" >> $HTMLDEST/rss.xml
        echo -e "\t\t\t<guid>http://npisanti.com/$pagelink</guid>" >> $HTMLDEST/rss.xml
        echo -e "\t\t</item>" >> $HTMLDEST/rss.xml

    fi
done < "$inputlist"

# rss tail 
echo -e "\t</channel>" >> $HTMLDEST/rss.xml
echo "</rss>" >> $HTMLDEST/rss.xml
sed -i -e "s|LASTYEARPLACEHOLDER|$lastyear|g" "$HTMLDEST/rss.xml"  
sed -i -e "s|LASTBUILDPLACEHOLDER|$lastbuild|g" "$HTMLDEST/rss.xml"  

echo "   - finished building RSS"

# --------------------------------------------------------------------
# ---------------- DATAPATHS -----------------------------------------
# --------------------------------------------------------------------

#sed -i -e "s|DATAPATH|$datapath|g" "$pagepath" 
for d in input/journal/*/ ; do
    dirname=$(echo $d | cut -d '/' -f3)
    for f in $(ls -1 "$HTMLDEST/$dirname" | sort -r)
    do
        #echo "operating on $HTMLDEST/$dirname/$f"
        sed -i -e "s|SITEROOTPATH|..|g" "$HTMLDEST/$dirname/$f" 
    done
done

for f in $(ls -1 "$HTMLDEST/main" | sort -r)
do
    sed -i -e "s|SITEROOTPATH|..|g" "$HTMLDEST/main/$f" 
done

for f in $(ls -1 "$HTMLDEST/posts" | sort -r)
do
    sed -i -e "s|SITEROOTPATH|..|g" "$HTMLDEST/posts/$f" 
done

sed -i -e "s|SITEROOTPATH/||g" "$HTMLDEST/index.html" 
sed -i -e "s|SITEROOTPATH/||g" "$HTMLDEST/more.html" 
sed -i -e "s|SITEROOTPATH/||g" "$HTMLDEST/contact.html" 
sed -i -e "s|SITEROOTPATH/||g" "$HTMLDEST/tcatnoc.html" 

# absolute urls to RSS 
sed -i -e "s|SITEROOTPATH|http://npisanti.com|g" "$HTMLDEST/rss.xml" 

# --------------------------------------------------------------------
# ---------------- RETROCOMPATIBILITY --------------------------------
# --------------------------------------------------------------------

mkdir -p $HTMLDEST/journal 
cp $HTMLDEST/rss.xml $HTMLDEST/journal/rss.xml 

exit