From: Banana Date: Sun, 9 Oct 2016 14:10:41 +0000 (+0200) Subject: s9y export to md and hugo static search X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=b35f5b5ebd441c50fa4f8752741a713e35c1b462;p=dolphin.git s9y export to md and hugo static search --- diff --git a/s9y-to-md/README b/s9y-to-md/README new file mode 100644 index 0000000..97a3bc1 --- /dev/null +++ b/s9y-to-md/README @@ -0,0 +1,5 @@ +A very simple export of the serendipity entries to a mardown file. +Use this as a base to get started and write your own export. + +This usese the pandoc commandline tool to convert the HTML to MD... +http://pandoc.org/ diff --git a/s9y-to-md/export.php b/s9y-to-md/export.php new file mode 100644 index 0000000..a6237d4 --- /dev/null +++ b/s9y-to-md/export.php @@ -0,0 +1,131 @@ +connect_errno) exit('Can not connect to MySQL Server'); +#$DB->set_charset("utf8mb4"); +#$DB->query("SET collation_connection = 'utf8mb4_bin'"); + +$workingDir = getcwd(); + +date_default_timezone_set('Europe/Berlin'); + +# get the tags as array per entrie +$tags = array(); +$queryStr = "SELECT * FROM serendipity_entrytags"; +$query = $DB->query($queryStr); +while($result = $query->fetch_assoc()) { + $tags[$result['entryid']][] = $result['tag']; +} + +$categories = array(); +$queryStr = "SELECT ec.entryid, c.category_name FROM `serendipity_entrycat` AS ec + LEFT JOIN serendipity_category as c ON ec.categoryid = c.categoryid"; +$query = $DB->query($queryStr); +while($result = $query->fetch_assoc()) { + $categories[$result['entryid']][] = $result['category_name']; +} + +# get the links and preformat them +$links = array(); +$queryStr = "SELECT * FROM serendipity_permalinks WHERE `type` = 'entry'"; +$query = $DB->query($queryStr); +while($result = $query->fetch_assoc()) { + $_link = $result['permalink']; + $_link = str_replace('archives/'.$result['entry_id'].'-','',$_link); + $_link = str_replace('.html','',$_link); + $_link = trim($_link, ' .,'); + $links[$result['entry_id']] = $_link; +} + +# get the entries +$queryStr = "SELECT * FROM serendipity_entries WHERE `isdraft` = 'false'"; +$query = $DB->query($queryStr); +while($result = $query->fetch_assoc()) { + $_tags = ''; + if(isset($tags[$result['id']])) { + $_tags = '"'.implode('","',$tags[$result['id']]).'"'; + } + $tagstring = $_tags; + + $_categories = ''; + if(isset($categories[$result['id']])) { + $_categories = '"'.implode('","',$categories[$result['id']]).'"'; + } + $category = '"Dev",'.$_categories; + $category = trim($category, " ,"); + + $filename = $result['id']; + if(isset($links[$result['id']])) { + $filename = $links[$result['id']]; + } + + $year = date("Y",$result['timestamp']); + $month = date("m",$result['timestamp']); + + if(!file_exists('output/'.$year)) { + mkdir('output/'.$year); + } + + if(!file_exists('output/'.$year.'/'.$month)) { + mkdir('output/'.$year.'/'.$month); + } + + $targetfile = 'output/'.$year.'/'.$month.'/'.$filename.".md"; + + $date = date("Y-m-d",$result['timestamp']); + $title = trim($result['title']); + $title = str_replace('"','',$title); + + $filedata = <<close(); diff --git a/s9y-to-md/output/.gitignore b/s9y-to-md/output/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/s9y-to-md/output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/static-hugo-search/README b/static-hugo-search/README new file mode 100644 index 0000000..d7e8d7f --- /dev/null +++ b/static-hugo-search/README @@ -0,0 +1,2 @@ +This is a very simple file search for the generated HTML files from hugo. +http://gohugo.io/ diff --git a/static-hugo-search/search.php b/static-hugo-search/search.php new file mode 100644 index 0000000..6dee5d5 --- /dev/null +++ b/static-hugo-search/search.php @@ -0,0 +1,167 @@ + 30) break; + + $stream = new SplFileObject($file); + $grepped = new RegexIterator($stream, '/'.$searchStr.'/'); + foreach($grepped as $found) { + $_text = $file; + + + $headlines = new RegexIterator($stream,"/

([^<]+)<\/h2>/"); + foreach($headlines as $headline) { + $_text = trim($headline); + $_text = strip_tags($_text); + break; + } + + + $searchResult[] = array( + 'href' => 'https://url.to/'.$file, + 'text' => $_text + ); + $limit++; + + #var_dump($found); + #var_dump($file); + #var_dump($searchResult); + #exit(); + + unset($headlines); + unset($_text); + break; + } + unset($stream); + unset($grepped); + } + $searchCount = count($searchResult); + } + } + + # is it a tag? + $tagDir = 'tags/'.$searchStr; + if(file_exists($tagDir)) { + $tagLink = $searchStr; + } + + # is it a category? + $topicsDir = 'topics/'.$searchStr; + if(file_exists($topicsDir)) { + $catLink = $searchStr; + } +} + +header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); +?> + + + + Suche nach: <?php echo $searchStr; ?> + + + + + + +
+ +
+
+

Suche

+

Gesucht: | Gefunden:

+
+ + +

Tag:

+ + +

Kategorie:

+ + + + + +
+

Leider nichts gefunden.

+
+ + +
+
+ + +