mandatory BASEURL config; [go-get] flag; canonicalisation; remove index.html paths by default
This commit is contained in:
parent
17f5355557
commit
1a0191a716
@ -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[] = '<link rel="canonical" href="'.hesc(BASEURL.$this->projname).'">'; // TODO include golang `go get` meta if necessary
|
||||
|
||||
if (strlen($this->go_get_target) > 0) {
|
||||
$extra_head_items[] = '<meta name="go-import" content="'.hesc($this->go_get_target).'">'; // 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 {
|
||||
<ul class="<?=$include_header ? 'downloads-large' : 'downloads-small' ?>">
|
||||
<?php foreach($render_downloads as $idx => $filename) { ?>
|
||||
<li>
|
||||
<a href="srv/<?=hesc($this->downloads_hashes[$idx])?>/<?=hesc(rawurlencode($filename))?>"><?=hesc($filename)?></a>
|
||||
<a href="<?=BASEURL?>srv/<?=hesc($this->downloads_hashes[$idx])?>/<?=hesc(rawurlencode($filename))?>"><?=hesc($filename)?></a>
|
||||
<small>
|
||||
<?=hesc(fbytes(filesize(BASEDIR.'wwwroot/srv/'.$this->downloads_hashes[$idx].'/'.$filename)))?>
|
||||
</small>
|
||||
@ -338,7 +358,7 @@ class CProject {
|
||||
<?php if (count($this->images)) { ?>
|
||||
<div class="projimg">
|
||||
<?php foreach($this->images as $idx => $origname) { ?>
|
||||
<a href="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
|
||||
<a href="<?=BASEURL?>img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>.<?=str_ext($origname)?>"><img src="img/<?=hesc(urlencode($this->projname))?>_<?=$idx?>_thumb.jpg" class="thumbimage"></a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
|
@ -29,6 +29,7 @@ function main($args) {
|
||||
}
|
||||
|
||||
define('BASEDIR', $basedir);
|
||||
define('BASEURL', trim($config['codesite']['baseurl']));
|
||||
define('SITE_TITLE', trim($config['codesite']['title']));
|
||||
define('PAGE_THUMB_W', intval($config['codesite']['page_thumb_w']));
|
||||
define('PAGE_THUMB_H', intval($config['codesite']['page_thumb_h']));
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
function template($title, $content) {
|
||||
function template($title, $content, $extra_head='') {
|
||||
ob_start();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@ -9,9 +9,10 @@ function template($title, $content) {
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
|
||||
<meta name="viewport" content="width=960" >
|
||||
<link type="text/css" rel="stylesheet" href="static/normalize.css">
|
||||
<link type="text/css" rel="stylesheet" href="static/style.css">
|
||||
<script type="text/javascript" src="static/site.js"></script>
|
||||
<?=$extra_head?>
|
||||
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/normalize.css">
|
||||
<link type="text/css" rel="stylesheet" href="<?=BASEURL?>static/style.css">
|
||||
<script type="text/javascript" src="<?=BASEURL?>static/site.js"></script>
|
||||
<title><?=hesc($title)?></title>
|
||||
</head>
|
||||
<body>
|
||||
@ -130,13 +131,13 @@ function buildcommon() {
|
||||
data-sort-ls="-<?=$pr->lifespan?>"
|
||||
>
|
||||
<td>
|
||||
<a href="<?=hesc(urlencode($pr->projname))?>.html"><?=(is_null($handle_lookup[$pr->projname]) ? '<div class="no-image"></div>' : '<div class="homeimage homeimage-sprite" style="background-position:0 -'.($handle_lookup[$pr->projname]*INDEX_THUMB_H).'px"></div>')?></a>
|
||||
<a href="<?=hesc(BASEURL.urlencode($pr->projname))?>/"><?=(is_null($handle_lookup[$pr->projname]) ? '<div class="no-image"></div>' : '<div class="homeimage homeimage-sprite" style="background-position:0 -'.($handle_lookup[$pr->projname]*INDEX_THUMB_H).'px"></div>')?></a>
|
||||
</td>
|
||||
<td>
|
||||
<strong><?=hesc(str_replace('_', ' ', $pr->projname))?></strong><?php if (SHOW_BLURBS) { ?>,
|
||||
<?=hesc($pr->shortdesc)?>
|
||||
<?php } ?>
|
||||
<a href="<?=hesc(urlencode($pr->projname))?>.html" class="article-read-more">more...</a>
|
||||
<a href="<?=hesc(BASEURL.urlencode($pr->projname))?>/" class="article-read-more">more...</a>
|
||||
<?php if (strlen($pr->subtag) || count($pr->tags)) { ?>
|
||||
<br>
|
||||
<small>
|
||||
@ -155,20 +156,26 @@ function buildcommon() {
|
||||
</table>
|
||||
<?php
|
||||
|
||||
$index = template(SITE_TITLE, ob_get_clean());
|
||||
$extra_head = '<link rel="canonical" href="'.hesc(BASEURL).'">';
|
||||
|
||||
$index = template(SITE_TITLE, ob_get_clean(), $extra_head);
|
||||
file_put_contents(BASEDIR.'wwwroot/index.html', $index);
|
||||
|
||||
// Done
|
||||
}
|
||||
|
||||
function buildredirects($redirects) {
|
||||
foreach($redirects as $oldname => $newname) {
|
||||
function redirecthtml($target) {
|
||||
ob_start();
|
||||
?>
|
||||
<meta http-equiv="refresh" content="0; url=<?=hesc($newname)?>.html">
|
||||
<a href="<?=hesc($newname)?>.html">Moved »</a>
|
||||
<meta http-equiv="refresh" content="0; url=<?=hesc($target)?>">
|
||||
<a href="<?=hesc($target)?>">Moved »</a>
|
||||
<?php
|
||||
$page = ob_get_clean();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
function buildredirects($redirects) {
|
||||
foreach($redirects as $oldname => $newname) {
|
||||
$page = redirecthtml($newname.'.html');
|
||||
file_put_contents(BASEDIR.'wwwroot/'.$oldname.'.html', $page);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user