fixing router for production

This commit is contained in:
Benjamin Sonntag 2015-08-07 15:17:02 +02:00
parent 818022df4a
commit 17ce98d5aa
3 changed files with 14 additions and 21 deletions

View File

@ -1,15 +0,0 @@
all: install_fr.html install_en.html home_fr.html home_en.html
install_fr.html: install_fr.md
github-markup install_fr.md >install_fr.html
install_en.html: install_en.md
github-markup install_en.md >install_en.html
home_fr.html: home_fr.md
github-markup home_fr.md >home_fr.html
home_en.html: home_en.md
github-markup home_en.md >home_en.html

View File

@ -3,5 +3,5 @@ Dependencies:
- bootstrap (included)
- github-markup https://github.com/github/markup (to be installed)
- make
- submodule git@github.com:AlternC/AlternC.wiki.git in pages/

View File

@ -3,7 +3,10 @@
// List here the supported languages :
$otherlang=array(
"fr" => "Français",
"en" => "English"
"en" => "English",
);
$locales=array("fr" => "fr_FR.UTF-8",
"en" => "en_GB.UTF-8",
);
$uri=trim($_SERVER["REQUEST_URI"],"/");
@ -21,12 +24,10 @@ if (!$uri) {
exit();
}
if (preg_match('^(.*)-([^-]*)$',$uri,$mat)) {
if (preg_match('#^(.*)-([^-]*)$#',$uri,$mat)) {
$lang=$mat[2];
$uri=$mat[1];
}
//list($lang,$uri)=explode("/",$uri,2);
if (!isset($otherlang[$lang])) {
header("HTTP/1.0 404 Not Found");
@ -34,6 +35,13 @@ if (!isset($otherlang[$lang])) {
exit();
}
// set locales:
putenv("LC_MESSAGES=".$locales[$lang]);
putenv("LANG=".$locales[$lang]);
putenv("LANGUAGE=".$locales[$lang]);
// this locale MUST be selected in "dpkg-reconfigure locales"
setlocale(LC_ALL,$locales[$lang]);
unset($otherlang[$lang]);
header("Content-Type: text/html; charset=UTF-8");
@ -47,7 +55,7 @@ if (!file_exists("../pages/".$uri."-".$lang.".md")) {
// automatic compilation / caching of HTML pages
if (!file_exists("../pages/".$uri."-".$lang.".html") ||
filemtime("../pages/".$uri."-".$lang.".html") < filemtime("../pages/".$uri."-".$lang.".md") ) {
exec("github-markup ".escapeshellarg("../pages/".$uri."-".$lang.".md")." >".escapeshellarg("../pages/".$uri."-".$lang.".html"));
passthru("github-markup ".escapeshellarg("../pages/".$uri."-".$lang.".md")." >".escapeshellarg("../pages/".$uri."-".$lang.".html")." 2>&1");
}
$f=fopen("../pages/".$uri."-".$lang.".html","rb");