Colibre: tdf#146410 update Clone Formatting icons
[LibreOffice.git] / solenv / bin / mkdocs_portal.sh
blob8fa120a77286edb0ca4065a3e4f3c7fddc74e2e0
1 #!/usr/bin/env bash
3 if [ -n "$debug" ] ; then
4 set -x
5 fi
7 markdown="markdown"
8 SRCDIR="$1"
9 BASE_OUTPUT="$2"
11 pushd "$SRCDIR" > /dev/null
14 function header
16 local title="$1"
17 local breadcrumb="$2"
18 local output="$3"
20 cat - > $output <<EOF
21 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
22 <html>
23 <head>
24 <title>$title</title>
26 <style>
27 * { margin: 0; padding: 0; }
28 body { font-family: sans-serif; font-size: 12px; }
29 #head { padding: 20px; background: #00A500; }
30 #head a { color: #000; }
31 #body { padding: 20px; }
32 #foot { padding: 10px; font-size: 9px; border-top: 1px #18A303 solid; margin-top: 25px; }
33 p { line-height: 1.7em; margin-bottom: 1em; }
34 pre { margin-bottom: 0.5em; }
35 .multi-col { -moz-column-width: 20em; -webkit-column-width: 20em; -moz-column-gap: 1em; -webkit-column-gap: 1em; }
36 h1 { margin-bottom: 0.5em; }
37 h2,h3,h4 { margin: 1.3em 0 0.5em 0; }
38 ul, ol { margin: 0.5em 1.5em; }
39 </style>
40 </head>
41 <body>
42 <div id="head">
43 <h1>${title}</h1>
44 <p>${breadcrumb}</p>
45 </div>
46 <div id="body" style="multi-col">
47 EOF
50 function footer
52 local output="$1"
54 cat - >> $output <<EOF
56 </div>
57 <div id="foot">
58 <small>
59 <p>Generated by Libreoffice CI on $(hostname)</p>
60 <p>Last updated:
61 EOF
63 date '+%F %T' >> $output
64 cat - >> $output <<EOF
65 | <a href="http://www.documentfoundation.org/privacy">Privacy Policy</a> | <a href="http://www.documentfoundation.org/imprint">Impressum (Legal Info)</a>
66 </p>
67 </small>
68 </div>
69 </body>
70 </html>
71 EOF
75 function proc_text
77 # Local links: [[...]]
78 # Git links: [git:...]
79 # Other remote links: [...]
80 # Headings: == bleh ==
81 # Paragraphs: \n\n
82 sed -re ' s/\[\[([-_a-zA-Z0-9]+)\]\]/<a href="\1.html">\1<\/a>/g' - \
83 | sed -re ' s/\[git:([^]]+)\]/<a href="https:\/\/git.libreoffice.org\/core\/+\/refs\/heads\/master\/\1">\1<\/a>/g' \
84 | sed -re ' s/\[([^]]+)\]/<a href="\1">\1<\/a>/g' \
85 | sed -re ' s/====([^=]+)====/<h4>\1<\/h4>/g' \
86 | sed -re ' s/===([^=]+)===/<h3>\1<\/h3>/g' \
87 | sed -re ' s/==([^=]+)==/<h2>\1<\/h2>/g' \
88 | sed -re ':a;N;$!ba;s/\n\n/<\/p><p>/g' \
89 | awk 'BEGIN { print "<p>" } { print } END { print "</p>" }'
92 function proc_text_markdown {
93 sed -re ' s/\[git:([^]]+)\]/<a href="https:\/\/git.libreoffice.org\/core\/+\/refs\/heads\/master\/\1">\1<\/a>/g'
96 # generate entry page
98 echo "generating index page"
99 header "LibreOffice Modules" " " "$BASE_OUTPUT/index.html"
101 for module_name in *; do
102 if [ -d $module_name ]; then
103 cur_file=$(echo $module_name/README.md)
104 if [ -f "$cur_file" ]; then
105 # write index.html entry
106 text=$(echo -e "<h2><a href=\"${module_name}.html\">${module_name}</a></h2>\n")
107 if [ ${cur_file: -3} == ".md" ]; then
108 # This is a markdown file.
109 header_text="$(head -n1 $cur_file)"
110 header_text="$(echo ${header_text} | sed -e 's/^\#*//g')"
111 text="${text}${header_text}"
112 else
113 text="${text}$(head -n1 $cur_file | proc_text)"
115 echo -e "$text" >> "$BASE_OUTPUT/index.html"
117 # write detailed module content
118 header "$module_name" "<a href=\"index.html\">LibreOffice</a> &raquo; ${module_name}" "$BASE_OUTPUT/${module_name}.html"
119 text="<p><b>View module in:</b>"
120 text="${text} &nbsp; <a href=\"https://git.libreoffice.org/core/+/refs/heads/master/${module_name}\">git</a>"
121 if $(echo $INPUT_PROJECTS | grep -q $module_name); then
122 text="${text} &nbsp; <a href=\"${module_name}/html/classes.html\">Doxygen</a>"
124 text="${text} </p><p>&nbsp;</p>"
125 echo -e "$text" >> "$BASE_OUTPUT/${module_name}.html"
127 if [ ${cur_file: -3} == ".md" ]; then
128 # This is a markdown file.
129 text="$(${markdown} $cur_file | proc_text_markdown)"
130 echo -e "$text" >> "$BASE_OUTPUT/${module_name}.html"
131 else
132 proc_text < $cur_file >> "$BASE_OUTPUT/${module_name}.html"
134 footer "$BASE_OUTPUT/${module_name}.html"
135 else
136 empty_modules[${#empty_modules[*]}]=$module_name
139 done
141 if [ ${#empty_modules[*]} -gt 10 ]; then
142 echo -e "<p>&nbsp;</p><p>READMEs were not available for these modules:</p><ul>\n" >> "$BASE_OUTPUT/index.html"
143 for module_name in "${empty_modules[@]}"; do
144 if [[ "$module_name" =~ ^(autom4te.cache|dictionaries|docs|helpcompiler|helpcontent2|include|instdir|lo|translations|workdir)$ ]]
145 then
146 continue
148 echo -e "<li><a href=\"https://git.libreoffice.org/core/+/refs/heads/master/${module_name}\">${module_name}</a></li>\n" >> "$BASE_OUTPUT/index.html"
149 done
150 echo -e "</ul>\n" >> "$BASE_OUTPUT/index.html"
153 footer "$BASE_OUTPUT/index.html"
155 popd > /dev/null
157 ## done