morpheus-site

morpheus.2f30.org website
git clone git://git.2f30.org/morpheus-site
Log | Files | Refs | README | LICENSE

generate.sh (4846B)


      1 #!/bin/sh
      2 # site title (part of ${pagetitle} probably).
      3 sitetitle="Morpheus Linux"
      4 # site language.
      5 sitelang="en"
      6 # main site domain.
      7 sitedomain="http://morpheus.2f30.org"
      8 # relative site url, can be "/blog" or something.
      9 siteurlrel=""
     10 # full site url.
     11 siteurlfull="${sitedomain}${siteurlrel}"
     12 # site keywords (global default), don't use too many.
     13 sitekeywords="morpheus, static, linux, distribution"
     14 # site description (global default).
     15 sitedescription="Morpheus, a simple statically-linked Linux distribution"
     16 # sitem mail used for contact "mail link".
     17 sitemail="admin@AT@morpheus DOT org"
     18 # site author (global).
     19 siteauthor="admin"
     20 # site last updated (default use date when script was run).
     21 siteupdated=$(date "+%Y-%m-%dT%H:%M:%SZ")
     22 # Directories containing content and metadata.
     23 # NOTE: it's recommended to use absolute paths here, use "." for current directory.
     24 pagesdir="pages"
     25 # Output dir.
     26 outputdir="output"
     27 # Markdown processor: default: is "smu".
     28 markdown="smu"
     29 
     30 #makeid(title), format "Some title" to "some-title".
     31 makeid() {
     32 	printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -e 's@[^a-zA-Z0-9]\+@-@g' \
     33 		-e 's@[-]*$@@g' -e 's@^[-]*@@g'
     34 }
     35 
     36 # initial values for page variables, use some site vars as global defaults.
     37 pagereset() {
     38 	id=""
     39 	title=""
     40 	url=""
     41 	description="${sitedescription}"
     42 	keywords="${sitekeywords}"
     43 	author="${siteauthor}"
     44 	content=""
     45 	tags=""
     46 	categories=""
     47 	timecreated=""
     48 	datecreated=""
     49 	timeupdated=""
     50 	dateupdated=""
     51 }
     52 
     53 pageread() {
     54 	meta="$1"
     55 	. "$meta" # source page metadata.
     56 	basename=$(basename "${meta}" ".sh")
     57 	datecreated=$(printf '%s' "${timecreated}" | cut -b 1-10)
     58 	dateupdated=$(printf '%s' "${timeupdated}" | cut -b 1-10)
     59 
     60 	# if ${id} is empty and title is set: create id based on title.
     61 	if [ "${id}" = "" ] && [ ! "${title}" = "" ]; then
     62 		id=$(makeid "${title}")
     63 	fi
     64 	if [ "${id}" = "" ]; then
     65 		printf '%s\n' "Warning: \$id or \$title not set in \"${meta}\", skipping..." >&2
     66 		continue
     67 	fi
     68 	if [ "${url}" = "" ]; then
     69 		url="${id}.html"
     70 	fi
     71 	outfile="${id}.html"
     72 	urlfull="${siteurlfull}/${outfile}"
     73 	filename=""
     74 	# ${content} not set; try data from filetypes.
     75 	if [ "${content}" = "" ]; then
     76 		if [ -f "${pagesdir}/${basename}.html" ]; then
     77 			filename="${pagesdir}/${basename}.html"
     78 			content=$(cat "${filename}")
     79 		elif [ -f "${pagesdir}/${basename}.md" ]; then
     80 			filename="${pagesdir}/${basename}.md"
     81 			content=$("${markdown}" "${filename}")
     82 		fi
     83 	fi
     84 }
     85 
     86 pageheader() {
     87 	# prefix page title with site title, make sure its neatly formatted.
     88 	if [ "${title}" = "" ]; then
     89 		pagetitle="${sitetitle}"
     90 	else
     91 		pagetitle="${title} - ${sitetitle}"
     92 	fi
     93 	cat <<!__EOF__
     94 <!DOCTYPE HTML>
     95 <html dir="ltr" lang="${sitelang}">
     96 	<head>
     97 		<title>${pagetitle}</title>
     98 		<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
     99 		<link rel="stylesheet" href="print.css" type="text/css" media="print" />
    100 		<link rel="icon" type="image/png" href="/favicon.png" />
    101 		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    102 		<meta http-equiv="Content-Language" content="${sitelang}" />
    103 		<meta content="width=device-width" name="viewport" />
    104 		<meta content="${keywords}" name="keywords" />
    105 		<meta content="${description}" name="description" />
    106 		<meta content="${author}" name="author" />
    107 	</head>
    108 	<body>
    109 		<div id="menuwrap">
    110 			<div id="menu">
    111 				<span id="links">
    112 					<img src="/favicon.png" width="32" height="32" alt="" valign="middle" /> <a href="index.html">Morpheus Linux</a> | 
    113 					<a href="http://git.2f30.org/morpheus/file/README.html" title="Installation instructions">Install</a> | 
    114 					<a href="http://morpheus.2f30.org/0.0/" title="morpheus v0.0 packages">Packages</a> |
    115 					<a href="http://morpheus.2f30.org/img/" title="morpheus v0.0 images">Images</a> |
    116 					<a href="community.html" title="Community">Community</a> | 
    117 					<a href="http://git.2f30.org/" title="Morpheus git">Git</a>
    118 				</span>
    119 			</div>
    120 		</div>
    121 		<hr class="hidden" />
    122 		<div id="mainwrap">
    123 			<div id="main">
    124 !__EOF__
    125 }
    126 
    127 pagecontent() {
    128 	pageheader
    129 	cat <<!__EOF__
    130 		${content}
    131 !__EOF__
    132 	pagefooter
    133 }
    134 
    135 pagefooter() {
    136 	cat <<!__EOF__
    137 			</div>
    138 		</div>
    139 	</body>
    140 </html>
    141 !__EOF__
    142 }
    143 
    144 if [ ! -d "${pagesdir}" ]; then
    145 	printf '%s\n' "Error: pages directory \"${pagesdir}\" not found." >&2
    146 	exit 1
    147 fi
    148 
    149 # process single page as argument (handy for testing a single page).
    150 if [ ! "$1" = "" ]; then
    151 	pagereset
    152 	pageread "$1"
    153 	pagecontent
    154 	exit 0
    155 fi
    156 
    157 # try to make output dir.
    158 mkdir -p "${outputdir}"
    159 
    160 while read -r meta; do
    161 	pagereset
    162 	pageread "$meta"
    163 	pagecontent > "${outputdir}/${outfile}"
    164 done <<!FILELIST
    165 $(find "${pagesdir}" -type f -name "*.sh" | sort -rn)
    166 !FILELIST
    167 # process pages (reverse numeric order).
    168 # NOTE: above heredoc is used to make sure content* variables are known
    169 # in the scope after the while loop (subshell / pipes prevents this in a
    170 # standard manner).