Skip to content

Commit

Permalink
A few improvements.
Browse files Browse the repository at this point in the history
- Relative links now work under Windows systems
- Added a few methods to the Page API
- Fixed verbose mesages
  • Loading branch information
sylvainhalle committed Oct 18, 2016
1 parent 9724d0e commit f0aec50
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
20 changes: 10 additions & 10 deletions fw/fw.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
/**************************************************************************
Fantastic Windmill
Copyright (C) 2013 Sylvain Hallé
Copyright (C) 2013-2016 Sylvain Hallé
A simple static web site generator for PHP programmers.
Author: Sylvain Hallé
Date: 2013-01-26
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -23,10 +22,10 @@
**************************************************************************/

// Version string (used for version tracking)
define("VERSION_STRING", "1.0.3");
define("VERSION_STRING", "1.0.4");
$HELLO_MSG = "Fantastic Windmill v".
VERSION_STRING." - A static web site generator for PHP programmers\n".
"(C) 2013 Sylvain Hallé, Université du Québec à Chicoutimi";
"(C) 2013-2016 Sylvain Hallé, Université du Québec à Chicoutimi";

$usage_string = <<<EOD
Expand Down Expand Up @@ -158,7 +157,7 @@
}

// Is there a YAML declaration at the end of the file?
preg_match("/^---\n.*$/ms", $contents, $matches, PREG_OFFSET_CAPTURE);
preg_match("/^---[\\r\\n].*$/ms", $contents, $matches, PREG_OFFSET_CAPTURE);
if (count($matches) > 0)
{
$yaml_contents = $matches[0][0];
Expand All @@ -181,7 +180,7 @@
@$page->parse($html_contents);
$nodelist = $page->dom->getElementsByTagName("h1");
$heading1 = $nodelist->item(0);
if (!isset($page->data["title"]))
if (isset($heading1) && !isset($page->data["title"]))
$page->data["title"] = $heading1->nodeValue;
if (!isset($page->data["abstract"]))
turn_blockquote_into_abstract($page);
Expand Down Expand Up @@ -228,7 +227,6 @@
$page_included_files = get_included_files();
$page_included_files = array_diff($page_included_files, $base_included_files);
$page->addIncludedFiles($page_included_files);
file_put_contents("/tmp/sample-page.html", $html_page);
@$page->parse($html_page);

// Rebase all absolute page URLs with respect to the document root
Expand Down Expand Up @@ -269,11 +267,13 @@
}
else
{
spit("Writing to $output_filename:", 1);
spit("Writing to $output_filename", 1);
if ($regenerate === Page::$FILE_MODIFIED)
spitln(" input file more recent than target file", 1);
spitln(": input file more recent than target file", 1);
elseif ($regenerate === Page::$FILE_DOES_NOT_EXIST)
spitln(": target file does not exist", 1);
else
spitln(" target file does not exist", 1);
spitln("", 1);
}
make_path($output_filename, true);
$contents = $page->dom->saveHTML();
Expand Down
18 changes: 14 additions & 4 deletions fw/page.inc.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
/**************************************************************************
Fantastic Windmill
Copyright (C) 2013 Sylvain Hallé
Copyright (C) 2013-2016 Sylvain Hallé
A simple static web site generator for PHP programmers.
Author: Sylvain Hallé
Date: 2013-01-26
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -57,12 +56,23 @@ public function getHtmlContents()
return $this->dom->saveHTML();
}

/**
* Gets the complete URL of the current page
*/
public function getUrl($from = "")
{
$my_filename = get_filename($this->m_outputFilename);
return $this->getPath($from).$my_filename;
}

/**
* Gets the folder of the current page (i.e. URL without filename)
*/
public function getPath($from = "")
{
$from_nofile = trim_filename($from);
$my_path = trim_filename($this->m_outputFilename);
$my_filename = get_filename($this->m_outputFilename);
$relative = relative_path($my_path, $from_nofile).$my_filename;
$relative = relative_path($my_path, $from_nofile);
return $relative;
}

Expand Down
11 changes: 5 additions & 6 deletions fw/rendering.inc.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
/**************************************************************************
Fantastic Windmill
Copyright (C) 2013 Sylvain Hallé
Copyright (C) 2013-2016 Sylvain Hallé
A simple static web site generator for PHP programmers.
Author: Sylvain Hallé
Date: 2013-01-23
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -32,22 +31,22 @@ class Rendering

public function getContentDir()
{
return $this->m_contentDir;
return to_slashes($this->m_contentDir);
}

public function getOutputDir()
{
return $this->m_outputDir;
return to_slashes($this->m_outputDir);
}

public function getStaticDir()
{
return $this->m_staticDir;
return to_slashes($this->m_staticDir);
}

public function getTemplateDir()
{
return $this->m_templateDir;
return to_slashes($this->m_templateDir);
}

public function getYaml()
Expand Down
5 changes: 2 additions & 3 deletions fw/site.inc.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
/**************************************************************************
Fantastic Windmill
Copyright (C) 2013 Sylvain Hallé
Copyright (C) 2013-2016 Sylvain Hallé
A simple static web site generator for PHP programmers.
Author: Sylvain Hallé
Date: 2013-01-23
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -53,7 +52,7 @@ public function setAuthor($s)

public function getBaseUrl()
{
return $this->m_baseUrl;
return to_slashes($this->m_baseUrl);
}

public function setBaseUrl($s)
Expand Down
11 changes: 9 additions & 2 deletions fw/utils.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php
/**************************************************************************
Fantastic Windmill
Copyright (C) 2013 Sylvain Hallé
Copyright (C) 2013-2016 Sylvain Hallé
A simple static web site generator for PHP programmers.
Author: Sylvain Hallé
Date: 2013-01-23
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -115,6 +114,8 @@ function make_path($pathname, $is_filename=false)
*/
function relative_path($p1, $p2)
{
$p1 = str_replace("\\", "/", $p1);
$p2 = str_replace("\\", "/", $p2);
if ($p1[strlen($p1) - 1] !== "/")
$p1 .= "/";
if ($p2[strlen($p2) - 1] !== "/")
Expand Down Expand Up @@ -149,6 +150,7 @@ function relative_path($p1, $p2)

function get_filename($s)
{
$s = to_slashes($s);
if ($pos = strrpos($s, "/"))
{
return substr($s, $pos + 1);
Expand Down Expand Up @@ -223,4 +225,9 @@ function turn_blockquote_into_abstract(&$page)
}
}

function to_slashes($s)
{
return str_replace("\\", "/", $s);
}

?>

0 comments on commit f0aec50

Please sign in to comment.