mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 11:16:00 +05:30
Support Multi Author
It has changed the structure of the folder content and some changes in functions.php and htmly.php, so that it can support multi-author.
This commit is contained in:
parent
441768bb1c
commit
32132caa3d
10 changed files with 182 additions and 87 deletions
3
content/admin/author.md
Normal file
3
content/admin/author.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Administrator #
|
||||
|
||||
I'm this blog administrator.
|
||||
3
content/admin/blog/2014-01-01_general_welcome.md
Normal file
3
content/admin/blog/2014-01-01_general_welcome.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Welcome #
|
||||
|
||||
Welcome to Example.com.
|
||||
3
content/admin/static/about.md
Normal file
3
content/admin/static/about.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# About
|
||||
|
||||
About this blog.
|
||||
3
content/admin/static/contact.md
Normal file
3
content/admin/static/contact.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Contact
|
||||
|
||||
Contact blog owner at contact@example.com.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Welcome #
|
||||
|
||||
Welcome Example.com.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# About
|
||||
|
||||
Edit this.
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Contact
|
||||
|
||||
Edit this.
|
||||
|
|
@ -4,11 +4,6 @@ site.url = ""
|
|||
; Blog info
|
||||
blog.title = "HTMLy"
|
||||
blog.description = "Databaseless Blogging Platform."
|
||||
|
||||
; Author info
|
||||
blog.author = "Admin"
|
||||
blog.authorid = "admin"
|
||||
blog.authorbio = "<p>I'm this blog admin.</p>"
|
||||
blog.copyright = "(c) Your name."
|
||||
|
||||
; Social account
|
||||
|
|
@ -51,4 +46,4 @@ default.thumbnail = ""
|
|||
views.root = "themes/default"
|
||||
|
||||
; Framework config. No need to edit.
|
||||
views.layout = "layout"
|
||||
views.layout = "layout"
|
||||
|
|
@ -90,46 +90,31 @@ get('/archive/:req',function($req){
|
|||
}
|
||||
|
||||
$time = explode('-', $req);
|
||||
|
||||
if (isset($time[0]))
|
||||
{
|
||||
$y = 'Y';
|
||||
}
|
||||
else {
|
||||
$y = '';
|
||||
}
|
||||
|
||||
if (isset($time[1]))
|
||||
{
|
||||
$m = 'F ';
|
||||
}
|
||||
else {
|
||||
$m = '';
|
||||
}
|
||||
|
||||
if (isset($time[2]))
|
||||
{
|
||||
$d = 'd ';
|
||||
}
|
||||
else {
|
||||
$d = '';
|
||||
}
|
||||
|
||||
$date = strtotime($req);
|
||||
|
||||
if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
|
||||
$timestamp = date('d F Y', $date);
|
||||
}
|
||||
else if (isset($time[0]) && isset($time[1])) {
|
||||
$timestamp = date('F Y', $date);
|
||||
}
|
||||
else {
|
||||
$timestamp = $req;
|
||||
}
|
||||
|
||||
if(!$date){
|
||||
// a non-existing page
|
||||
not_found();
|
||||
}
|
||||
|
||||
render('main',array(
|
||||
'title' => 'Archive - ' . date($d . $m . $y, $date) .' - ' . config('blog.title'),
|
||||
'title' => 'Archive - ' . $timestamp .' - ' . config('blog.title'),
|
||||
'page' => $page,
|
||||
'posts' => $posts,
|
||||
'canonical' => config('site.url') . '/archive/' . $req,
|
||||
'description' => 'Archive page for ' . date($d . $m . $y, $date) . ' on ' . config('blog.title') . '.',
|
||||
'description' => 'Archive page for ' . $timestamp . ' on ' . config('blog.title') . '.',
|
||||
'bodyclass' => 'inarchive',
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> » Archive for ' . date($d . $m . $y, $date),
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> » Archive for ' . $timestamp,
|
||||
'pagination' => has_pagination($total, $perpage, $page)
|
||||
));
|
||||
});
|
||||
|
|
@ -226,22 +211,22 @@ get('/:spage', function($spage){
|
|||
});
|
||||
|
||||
// The author page
|
||||
get('/author/' . config('blog.authorid'), function(){
|
||||
get('/author/:author', function($author){
|
||||
|
||||
$user= new stdClass;
|
||||
|
||||
$user->body = config('blog.authorbio');
|
||||
$user->title = config('blog.author');
|
||||
$user->authorurl = config('site.url') . '/author/' . config('blog.authorid');
|
||||
$post = find_author($author);
|
||||
|
||||
if(!$post){
|
||||
not_found();
|
||||
}
|
||||
|
||||
render('post',array(
|
||||
'title' => $user->title .' - ' . config('blog.title'),
|
||||
'canonical' => $user->authorurl,
|
||||
'description' => $description = get_description($user->body),
|
||||
'bodyclass' => 'inprofile',
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> » ' . $user->title,
|
||||
'p' => $user,
|
||||
'type' => 'profile',
|
||||
'title' => $post->title .' - ' . config('blog.title'),
|
||||
'canonical' => $post->url,
|
||||
'description' => $description = get_description($post->body),
|
||||
'bodyclass' => 'inpage',
|
||||
'breadcrumb' => '<a href="' . config('site.url') . '">Home</a> » ' . $post->title,
|
||||
'p' => $post,
|
||||
'type' => 'profilepage',
|
||||
));
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ function get_post_names(){
|
|||
// Get the names of all the
|
||||
// posts (newest first):
|
||||
|
||||
$_cache = array_reverse(glob('content/blog/*.md'));
|
||||
$_cache = array_reverse(glob('content/*/blog/*.md'));
|
||||
}
|
||||
|
||||
return $_cache;
|
||||
|
|
@ -34,7 +34,23 @@ function get_spage_names(){
|
|||
// Get the names of all the
|
||||
// static page (newest first):
|
||||
|
||||
$_cache = array_reverse(glob('content/static/*.md'));
|
||||
$_cache = glob('content/*/static/*.md', GLOB_NOSORT);
|
||||
}
|
||||
|
||||
return $_cache;
|
||||
}
|
||||
|
||||
// Get author bio
|
||||
function get_author_names(){
|
||||
|
||||
static $_cache = array();
|
||||
|
||||
if(empty($_cache)){
|
||||
|
||||
// Get the names of all the
|
||||
// author:
|
||||
|
||||
$_cache = glob('content/*/author.md', GLOB_NOSORT);
|
||||
}
|
||||
|
||||
return $_cache;
|
||||
|
|
@ -64,21 +80,28 @@ function get_posts($page = 1, $perpage = 0){
|
|||
// Extract the date
|
||||
$arr = explode('_', $v);
|
||||
|
||||
// Replaced string
|
||||
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
|
||||
|
||||
// Author string
|
||||
$str = explode('/', $replaced);
|
||||
$author = $str[count($str)-3];
|
||||
|
||||
// The post author + author url
|
||||
$post->author = config('blog.author');
|
||||
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
|
||||
$post->author = $author;
|
||||
$post->authorurl = site_url() . 'author/' . $author;
|
||||
|
||||
// The post date
|
||||
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
|
||||
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
|
||||
|
||||
// The archive per day
|
||||
$post->archive = site_url(). str_replace('content/blog/','archive/',$arr[0]);
|
||||
$post->archive = site_url(). 'archive/' . date('Y-m-d', $post->date) ;
|
||||
|
||||
// The post URL
|
||||
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
|
||||
|
||||
// The post tag
|
||||
$post->tag = str_replace('content/blog/','',$arr[1]);
|
||||
$post->tag = str_replace($replaced,'',$arr[1]);
|
||||
|
||||
// The post tag url
|
||||
$post->tagurl = site_url(). 'tag/' . $arr[1];
|
||||
|
|
@ -164,18 +187,25 @@ function get_tag($tag){
|
|||
// Make sure the tag request available
|
||||
if ($tag === $arr[1]) {
|
||||
|
||||
// Replaced string
|
||||
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
|
||||
|
||||
// Author string
|
||||
$str = explode('/', $replaced);
|
||||
$author = $str[count($str)-3];
|
||||
|
||||
// The post author + author url
|
||||
$post->author = config('blog.author');
|
||||
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
|
||||
$post->author = $author;
|
||||
$post->authorurl = site_url() . 'author/' . $author;
|
||||
|
||||
// The post date
|
||||
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
|
||||
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
|
||||
|
||||
// The post URL
|
||||
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
|
||||
|
||||
// The post tag
|
||||
$post->tag = str_replace('content/blog/','',$arr[1]);
|
||||
$post->tag = str_replace($replaced,'',$arr[1]);
|
||||
|
||||
// The post tag URL
|
||||
$post->tagurl = site_url(). 'tag/' . $arr[1];
|
||||
|
|
@ -216,18 +246,25 @@ function get_archive($req){
|
|||
// Extract the date
|
||||
$arr = explode('_', $v);
|
||||
|
||||
// Replaced string
|
||||
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
|
||||
|
||||
// Author string
|
||||
$str = explode('/', $replaced);
|
||||
$author = $str[count($str)-3];
|
||||
|
||||
// The post author + author url
|
||||
$post->author = config('blog.author');
|
||||
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
|
||||
$post->author = $author;
|
||||
$post->authorurl = site_url() . 'author/' . $author;
|
||||
|
||||
// The post date
|
||||
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
|
||||
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
|
||||
|
||||
// The post URL
|
||||
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
|
||||
|
||||
// The post tag
|
||||
$post->tag = str_replace('content/blog/','',$arr[1]);
|
||||
$post->tag = str_replace($replaced,'',$arr[1]);
|
||||
|
||||
// The post tag URL
|
||||
$post->tagurl = site_url(). 'tag/' . $arr[1];
|
||||
|
|
@ -257,7 +294,12 @@ function archive_list() {
|
|||
foreach($posts as $index => $v){
|
||||
|
||||
$arr = explode('_', $v);
|
||||
$date = str_replace('content/blog/','',$arr[0]);
|
||||
|
||||
// Replaced string
|
||||
$str = $arr[0];
|
||||
$replaced = substr($str, 0,strrpos($str, '/')) . '/';
|
||||
|
||||
$date = str_replace($replaced,'',$arr[0]);
|
||||
$data = explode('-', $date);
|
||||
$col[] = $data;
|
||||
|
||||
|
|
@ -312,8 +354,11 @@ function get_spage($posts, $spage){
|
|||
// Extract the array
|
||||
$arr = explode('_', $v);
|
||||
|
||||
// Replaced string
|
||||
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
|
||||
|
||||
// The static page URL
|
||||
$url = str_replace('content/static/','',$arr[0]);
|
||||
$url = str_replace($replaced,'',$arr[0]);
|
||||
$post->url = site_url() . str_replace('.md','',$url);
|
||||
|
||||
// Get the contents and convert it to HTML
|
||||
|
|
@ -350,6 +395,68 @@ function find_spage($spage){
|
|||
return false;
|
||||
}
|
||||
|
||||
// Return author page
|
||||
function get_author($names, $author){
|
||||
|
||||
$tmp = array();
|
||||
|
||||
// Create a new instance of the markdown parser
|
||||
$md = new MarkdownParser();
|
||||
|
||||
foreach($names as $index => $v){
|
||||
|
||||
$post = new stdClass;
|
||||
|
||||
// Extract the array
|
||||
$arr = explode('_', $v);
|
||||
|
||||
// Replaced string
|
||||
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
|
||||
|
||||
// Author string
|
||||
$str = explode('/', $replaced);
|
||||
$profile = $str[count($str)-2];
|
||||
|
||||
if($author === $profile){
|
||||
// Profile URL
|
||||
$url = str_replace($replaced,'',$arr[0]);
|
||||
$post->url = site_url() . 'author/' . $profile;
|
||||
|
||||
// Get the contents and convert it to HTML
|
||||
$content = $md->transformMarkdown(file_get_contents($v));
|
||||
|
||||
// Extract the title and body
|
||||
$arr = explode('</h1>', $content);
|
||||
$post->title = str_replace('<h1>','',$arr[0]);
|
||||
$post->body = $arr[1];
|
||||
|
||||
$tmp[] = $post;
|
||||
}
|
||||
else {
|
||||
not_found();
|
||||
}
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Find static page
|
||||
function find_author($author){
|
||||
|
||||
$names = get_author_names();
|
||||
|
||||
foreach($names as $index => $v){
|
||||
if( strpos($v, $author) !== false && strpos($v, 'author.md') !== false){
|
||||
// Use the get_spage method to return
|
||||
// a properly parsed object
|
||||
$arr = get_author($names, $author);
|
||||
return $arr[0];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return search page
|
||||
function get_keyword($keyword){
|
||||
|
||||
|
|
@ -370,20 +477,25 @@ function get_keyword($keyword){
|
|||
// Extract the date
|
||||
$arr = explode('_', $v);
|
||||
|
||||
// Make sure the tag request available
|
||||
// Replaced string
|
||||
$replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
|
||||
|
||||
// Author string
|
||||
$str = explode('/', $replaced);
|
||||
$author = $str[count($str)-3];
|
||||
|
||||
// The post author + author url
|
||||
$post->author = config('blog.author');
|
||||
$post->authorurl = site_url() . 'author/' . config('blog.authorid');
|
||||
$post->author = $author;
|
||||
$post->authorurl = site_url() . 'author/' . $author;
|
||||
|
||||
// The post date
|
||||
$post->date = strtotime(str_replace('content/blog/','',$arr[0]));
|
||||
$post->date = strtotime(str_replace($replaced,'',$arr[0]));
|
||||
|
||||
// The post URL
|
||||
$post->url = site_url().date('Y/m', $post->date).'/'.str_replace('.md','',$arr[2]);
|
||||
|
||||
// The post tag
|
||||
$post->tag = str_replace('content/blog/','',$arr[1]);
|
||||
$post->tag = str_replace($replaced,'',$arr[1]);
|
||||
|
||||
// The post tag URL
|
||||
$post->tagurl = site_url(). 'tag/' . $arr[1];
|
||||
|
|
@ -604,16 +716,16 @@ function publisher(){
|
|||
function analytics(){
|
||||
$analytics = config('google.analytics.id');
|
||||
$script = <<<EOF
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', '{$analytics}']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', '{$analytics}']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
EOF;
|
||||
if (!empty($analytics)) {
|
||||
return $script;
|
||||
|
|
@ -661,4 +773,4 @@ function generate_rss($posts){
|
|||
// Turn an array of posts into a JSON
|
||||
function generate_json($posts){
|
||||
return json_encode($posts);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue