From e571cb85cd9192f6a71411eb22a833a5646b089a Mon Sep 17 00:00:00 2001 From: Inndy Date: Fri, 13 Feb 2015 14:42:37 +0800 Subject: [PATCH 1/3] Add dependency: parsedown --- .gitmodules | 3 +++ parsedown | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 parsedown diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f87b777 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "parsedown"] + path = parsedown + url = https://github.com/erusev/parsedown.git diff --git a/parsedown b/parsedown new file mode 160000 index 0000000..65116c3 --- /dev/null +++ b/parsedown @@ -0,0 +1 @@ +Subproject commit 65116c3cb0953447eac742aa4ea5fc4aaaa22db9 From 9e59c80e4a92a7e10c524bbe6fc4b4f8caceaf00 Mon Sep 17 00:00:00 2001 From: Inndy Date: Fri, 13 Feb 2015 15:30:05 +0800 Subject: [PATCH 2/3] Use pathinfo to parse filename and extension name --- index.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/index.php b/index.php index ed76d68..bc5339b 100644 --- a/index.php +++ b/index.php @@ -51,14 +51,27 @@ function Diary($SingleDiary) * Get all the diary files */ -foreach(glob(__DIR__ . '/diary/*.txt') as $Diary) +foreach(glob(__DIR__ . '/diary/*') as $Diary) { /** The file name is the title of this diary */ - /** Now we remove the path first, then we remove the file extension */ - $Title = preg_replace('/\.\w*$/', '', preg_replace('/^.+[\\\\\\/]/', '', $Diary)); + $info = pathinfo($Diary); + $extension = $info['extension']; + + $Title = $info['filename']; + $Content = null; + /** Get the content */ - $Content = nl2br(file_get_contents($Diary)); + switch ($extension) { + case 'txt': + case 'text': + $Content = nl2br(file_get_contents($Diary)); + break; + } + + if ($Content === null) { + continue; // Skip invalid file type + } /** Get the unix timestramp of the file */ $Date = filemtime($Diary); From c439850f880954ea4c418964e8e284a71b000d35 Mon Sep 17 00:00:00 2001 From: Inndy Date: Fri, 13 Feb 2015 15:30:59 +0800 Subject: [PATCH 3/3] Add markdown support --- diary/Markdown is supported now.md | 15 +++++++++++++++ index.php | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 diary/Markdown is supported now.md diff --git a/diary/Markdown is supported now.md b/diary/Markdown is supported now.md new file mode 100644 index 0000000..5de82ea --- /dev/null +++ b/diary/Markdown is supported now.md @@ -0,0 +1,15 @@ +We are glad to announce that ... + +# Markdown Supported + +``` javascript +for (var i = 0; i < 10; i++) { + document.write("Hello from Inndy (" + i + ")
"); +} +``` + +~~Line-through test~~ *Italic* **Bold** ***ItalicBold*** + +--- + +Markdown renderer takes from [parsedown](https://github.com/erusev/parsedown). diff --git a/index.php b/index.php index bc5339b..fbac168 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ text(file_get_contents($Diary)); + break; case 'txt': case 'text': $Content = nl2br(file_get_contents($Diary));