From 1a0191a716e77823819ec5903a8799be652c03fa Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 17 Jul 2016 16:13:59 +1200 Subject: [PATCH] mandatory BASEURL config; [go-get] flag; canonicalisation; remove index.html paths by default --- lib/CProject.php | 28 ++++++++++++++++++++++++---- lib/bootstrap.php | 1 + lib/template.php | 33 ++++++++++++++++++++------------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/lib/CProject.php b/lib/CProject.php index a7e582b..62a8e4c 100644 --- a/lib/CProject.php +++ b/lib/CProject.php @@ -24,6 +24,8 @@ class CProject { public $homeimage = null; + protected $go_get_target = ''; + public function __construct($dirname, $projname) { $this->dir = BASEDIR.'data/'.$dirname.'/'; $this->projname = $projname; @@ -71,6 +73,12 @@ class CProject { $this->subtag = rtrim($matches[1], ' .'); } + // Find `go-get` tags + $this->longdesc = preg_replace_callback('~\[go-get\](.+)\[/go-get\]~', function($matches) { + $this->go_get_target = $matches[1]; + return ''; + }, $this->longdesc); + // Find tags if (preg_match('~Tags: ([^\\n]+)~', $this->longdesc, $matches)) { $this->tags = array_map('trim', explode(',', $matches[1])); @@ -269,8 +277,20 @@ class CProject { ob_start(); $this->index(); - $idxfile = template($this->projname.' | '.SITE_TITLE, ob_get_clean()); - file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', $idxfile); + + $extra_head_items = []; + + $extra_head_items[] = ''; // TODO include golang `go get` meta if necessary + + if (strlen($this->go_get_target) > 0) { + $extra_head_items[] = ''; // TODO include golang `go get` meta if necessary + } + + $idxfile = template($this->projname.' | '.SITE_TITLE, ob_get_clean(), implode("\n", $extra_head_items)); + mkdir(BASEDIR.'wwwroot/'.$this->projname); + + file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'/index.html', $idxfile); // new URL format + file_put_contents(BASEDIR.'wwwroot/'.$this->projname.'.html', redirecthtml(BASEURL.$this->projname)); // old URL format } public function getClassAttr() { @@ -294,7 +314,7 @@ class CProject {