Version 1.4.0 deleted unneccessary files
This commit is contained in:
parent
c1c40924db
commit
86dd36fb27
19 changed files with 0 additions and 773 deletions
|
@ -1,11 +0,0 @@
|
|||
# mdfixes
|
||||
|
||||
Content and some more.
|
||||
## This is headline second order
|
||||
This is a little bit of text that we need to have nothing
|
||||
|
||||
Some more text.
|
||||
|
||||
# And a headline first order
|
||||
|
||||
With some more text below.
|
|
@ -1 +0,0 @@
|
|||
["# mdfixes","Content and some more. Danke","## This is headline second order","This is a little bit of text that we need to have nothing","Some more text.","# And a headline first order","With some more text below."]
|
|
@ -1,9 +0,0 @@
|
|||
meta:
|
||||
title: mdfixes
|
||||
description: "Content and some more. This is headline second order\nThis is a little bit of text that we need to have."
|
||||
owner: trendschau
|
||||
author: 'Sebastian Schürmanns'
|
||||
created: '2020-10-01'
|
||||
time: 20-40-00
|
||||
navtitle: mdfixes
|
||||
modified: '2020-10-01'
|
|
@ -1,26 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Plugins\blurbbox;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
|
||||
class blurbbox extends plugin
|
||||
{
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'onPageReady' => 'onPageReady',
|
||||
);
|
||||
}
|
||||
|
||||
public function onPageReady($page)
|
||||
{
|
||||
$pageData = $page->getData($page);
|
||||
|
||||
$pageData['widgets']['blurbbox'] = '<div><p>Notes on (mostly) daily perceptions and experiences by Joseph Zitt, an American immigrant to Israel.</p>' .
|
||||
'<p><a href="http://www.josephzitt.com/home/books/as-if-in-dreams-notes-following-aliyah/">Buy the book.</a></p>' .
|
||||
'<p><a href="https://buttondown.email/josephzitt">Subscribe to the weekly newsletter.</a></p></div>';
|
||||
|
||||
$page->setData($pageData);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
name: Blurbbox
|
||||
version: 1.0.0
|
||||
description: Add a search to your website with lunr.js.
|
||||
author: Trendschau
|
||||
homepage: https://typemill.net
|
||||
licence: MIT
|
||||
paypal: https://paypal.me/typemill
|
||||
amount: 10
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Plugins\search;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
use \Typemill\Models\Write;
|
||||
use \Typemill\Models\WriteCache;
|
||||
|
||||
class Index extends Plugin
|
||||
{
|
||||
public static function getSubscribedEvents(){}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$write = new Write();
|
||||
|
||||
$index = $write->getFile('cache', 'index.json');
|
||||
if(!$index)
|
||||
{
|
||||
$this->createIndex();
|
||||
$index = $write->getFile('cache', 'index.json');
|
||||
}
|
||||
|
||||
return $this->returnJson($index);
|
||||
}
|
||||
|
||||
private function createIndex()
|
||||
{
|
||||
$write = new WriteCache();
|
||||
|
||||
# get content structure
|
||||
$structure = $write->getCache('cache', 'structure.txt');
|
||||
|
||||
# get data for search-index
|
||||
$index = $this->getAllContent($structure, $write);
|
||||
|
||||
# store the index file here
|
||||
$write->writeFile('cache', 'index.json', json_encode($index, JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
private function getAllContent($structure, $write, $index = NULL)
|
||||
{
|
||||
foreach($structure as $item)
|
||||
{
|
||||
if($item->elementType == "folder")
|
||||
{
|
||||
if($item->fileType == 'md')
|
||||
{
|
||||
$page = $write->getFileWithPath('content' . $item->path . DIRECTORY_SEPARATOR . 'index.md');
|
||||
$pageArray = $this->getPageContentArray($page, $item->urlAbs);
|
||||
$index[$pageArray['url']] = $pageArray;
|
||||
}
|
||||
|
||||
$index = $this->getAllContent($item->folderContent, $write, $index);
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = $write->getFileWithPath('content' . $item->path);
|
||||
$pageArray = $this->getPageContentArray($page, $item->urlAbs);
|
||||
$index[$pageArray['url']] = $pageArray;
|
||||
}
|
||||
}
|
||||
return $index;
|
||||
}
|
||||
|
||||
private function getPageContentArray($page, $url)
|
||||
{
|
||||
$parts = explode("\n", $page, 2);
|
||||
|
||||
# get the title / headline
|
||||
$title = trim($parts[0], '# ');
|
||||
$title = str_replace(["\r\n", "\n", "\r"],' ', $title);
|
||||
|
||||
# get and cleanup the content
|
||||
$content = $parts[1];
|
||||
$content = strip_tags($content);
|
||||
$content = str_replace(["\r\n", "\n", "\r"],' ', $content);
|
||||
|
||||
$pageContent = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'url' => $url
|
||||
];
|
||||
|
||||
return $pageContent;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (C) 2013 by Oliver Nightingale
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
6
plugins/blurbbox/public/lunr.min.js
vendored
6
plugins/blurbbox/public/lunr.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,64 +0,0 @@
|
|||
.searchContainer{
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.searchContainer input{
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 1rem;
|
||||
float: left;
|
||||
padding-left: 15px;
|
||||
border-radius: 2px;
|
||||
box-sizing:border-box;
|
||||
}
|
||||
.searchContainer button{
|
||||
border-top-right-radius: 2px;
|
||||
border-bottom-right-radius: 2px;
|
||||
border: none;
|
||||
background: #232833;
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
font-size: 10pt;
|
||||
margin-left: -50px;
|
||||
}
|
||||
.searchContainer button:hover,.searchContainer button:focus, .searchContainer button:active{
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#searchresult{
|
||||
}
|
||||
.resultwrapper{
|
||||
}
|
||||
button#closeSearchResult{
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
top: 0px;
|
||||
margin: 10px;
|
||||
border: none;
|
||||
border-radius: 2px;
|
||||
font-size: 1rem;
|
||||
color: #fff;
|
||||
background: #000;
|
||||
padding: 15px;
|
||||
}
|
||||
button#closeSearchResult:hover,#closeSearchResult:focus{
|
||||
cursor: pointer;
|
||||
}
|
||||
.resultlist{
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
list-style:none;
|
||||
}
|
||||
.resultitem{
|
||||
|
||||
}
|
||||
.resultheader{
|
||||
|
||||
}
|
||||
.resultsnippet{
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
var searchField = document.getElementById("searchField");
|
||||
var searchButton = document.getElementById("searchButton");
|
||||
|
||||
if(searchField && searchButton)
|
||||
{
|
||||
var searchIndex = false;
|
||||
var documents = false;
|
||||
var holdcontent = false;
|
||||
var contentwrapper = false;
|
||||
|
||||
searchField.addEventListener("focus", function(event){
|
||||
|
||||
if(!searchIndex)
|
||||
{
|
||||
myaxios.get('/indexrs51gfe2o2')
|
||||
.then(function (response) {
|
||||
|
||||
documents = JSON.parse(response.data);
|
||||
|
||||
searchIndex = lunr(function() {
|
||||
this.ref("id");
|
||||
this.field("title", { boost: 10 });
|
||||
this.field("content");
|
||||
for (var key in documents){
|
||||
this.add({
|
||||
"id": documents[key].url,
|
||||
"title": documents[key].title,
|
||||
"content": documents[key].content
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
.catch(function (error) {});
|
||||
}
|
||||
});
|
||||
|
||||
searchButton.addEventListener("click", function(event){
|
||||
event.preventDefault();
|
||||
|
||||
var term = document.getElementById('searchField').value;
|
||||
var results = searchIndex.search(term);
|
||||
|
||||
var resultPages = results.map(function (match) {
|
||||
return documents[match.ref];
|
||||
});
|
||||
|
||||
resultsString = "<div class='resultwrapper'><h1>Result for " + term + "</h1>";
|
||||
resultsString += "<button id='closeSearchResult'>close</button>";
|
||||
resultsString += "<ul class='resultlist'>";
|
||||
resultPages.forEach(function (r) {
|
||||
resultsString += "<li class='resultitem'>";
|
||||
resultsString += "<a class='resultheader' href='" + r.url + "?q=" + term + "'><h3>" + r.title + "</h3></a>";
|
||||
resultsString += "<div class='resultsnippet'>" + r.content.substring(0, 200) + " ...</div>";
|
||||
resultsString += "</li>"
|
||||
});
|
||||
resultsString += "</ul></div>";
|
||||
|
||||
if(!holdcontent)
|
||||
{
|
||||
contentwrapper = document.getElementById("searchresult").parentNode;
|
||||
holdcontent = contentwrapper.innerHTML;
|
||||
}
|
||||
|
||||
contentwrapper.innerHTML = resultsString;
|
||||
|
||||
document.getElementById("closeSearchResult").addEventListener("click", function(event){
|
||||
contentwrapper.innerHTML = holdcontent;
|
||||
});
|
||||
|
||||
}, false);
|
||||
}
|
||||
|
||||
/*
|
||||
var searchIndex = lunr(function() {
|
||||
this.ref("id");
|
||||
this.field("title", { boost: 10 });
|
||||
this.field("content");
|
||||
for (var key in window.pages) {
|
||||
this.add({
|
||||
"id": key,
|
||||
"title": pages[key].title,
|
||||
"content": pages[key].content
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function getQueryVariable(variable) {
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if (pair[0] === variable) {
|
||||
return decodeURIComponent(pair[1].replace(/\+/g, "%20"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var searchTerm = getQueryVariable("q");
|
||||
// creation of searchIndex from earlier example
|
||||
var results = searchIndex.search(searchTerm);
|
||||
var resultPages = results.map(function (match) {
|
||||
return pages[match.ref];
|
||||
});
|
||||
|
||||
// resultPages from previous example
|
||||
resultsString = "";
|
||||
resultPages.forEach(function (r) {
|
||||
resultsString += "<li>";
|
||||
resultsString += "<a class='result' href='" + r.url + "?q=" + searchTerm + "'><h3>" + r.title + "</h3></a>";
|
||||
resultsString += "<div class='snippet'>" + r.content.substring(0, 200) + "</div>";
|
||||
resultsString += "</li>"
|
||||
});
|
||||
document.querySelector("#search-results").innerHTML = resultsString;
|
||||
*/
|
Binary file not shown.
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Plugins\search;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
use \Typemill\Models\Write;
|
||||
use \Typemill\Models\WriteCache;
|
||||
|
||||
class Index extends Plugin
|
||||
{
|
||||
public static function getSubscribedEvents(){}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$write = new Write();
|
||||
|
||||
$index = $write->getFile('cache', 'index.json');
|
||||
if(!$index)
|
||||
{
|
||||
$this->createIndex();
|
||||
$index = $write->getFile('cache', 'index.json');
|
||||
}
|
||||
|
||||
return $this->returnJson($index);
|
||||
}
|
||||
|
||||
private function createIndex()
|
||||
{
|
||||
$write = new WriteCache();
|
||||
|
||||
# get content structure
|
||||
$structure = $write->getCache('cache', 'structure.txt');
|
||||
|
||||
# get data for search-index
|
||||
$index = $this->getAllContent($structure, $write);
|
||||
|
||||
# store the index file here
|
||||
$write->writeFile('cache', 'index.json', json_encode($index, JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
private function getAllContent($structure, $write, $index = NULL)
|
||||
{
|
||||
foreach($structure as $item)
|
||||
{
|
||||
if($item->elementType == "folder")
|
||||
{
|
||||
if($item->fileType == 'md')
|
||||
{
|
||||
$page = $write->getFileWithPath('content' . $item->path . DIRECTORY_SEPARATOR . 'index.md');
|
||||
$pageArray = $this->getPageContentArray($page, $item->urlAbs);
|
||||
$index[$pageArray['url']] = $pageArray;
|
||||
}
|
||||
|
||||
$index = $this->getAllContent($item->folderContent, $write, $index);
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = $write->getFileWithPath('content' . $item->path);
|
||||
$pageArray = $this->getPageContentArray($page, $item->urlAbs);
|
||||
$index[$pageArray['url']] = $pageArray;
|
||||
}
|
||||
}
|
||||
return $index;
|
||||
}
|
||||
|
||||
private function getPageContentArray($page, $url)
|
||||
{
|
||||
$parts = explode("\n", $page, 2);
|
||||
|
||||
# get the title / headline
|
||||
$title = trim($parts[0], '# ');
|
||||
$title = str_replace(["\r\n", "\n", "\r"],' ', $title);
|
||||
|
||||
# get and cleanup the content
|
||||
$content = $parts[1];
|
||||
$content = strip_tags($content);
|
||||
$content = str_replace(["\r\n", "\n", "\r"],' ', $content);
|
||||
|
||||
$pageContent = [
|
||||
'title' => $title,
|
||||
'content' => $content,
|
||||
'url' => $url
|
||||
];
|
||||
|
||||
return $pageContent;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (C) 2013 by Oliver Nightingale
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
6
plugins/search/public/lunr.min.js
vendored
6
plugins/search/public/lunr.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,64 +0,0 @@
|
|||
.searchContainer{
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.searchContainer input{
|
||||
width: 100%;
|
||||
height: 50px;
|
||||
border: 1px solid #ddd;
|
||||
font-size: 1rem;
|
||||
float: left;
|
||||
padding-left: 15px;
|
||||
border-radius: 2px;
|
||||
box-sizing:border-box;
|
||||
}
|
||||
.searchContainer button{
|
||||
border-top-right-radius: 2px;
|
||||
border-bottom-right-radius: 2px;
|
||||
border: none;
|
||||
background: #232833;
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
color: #fff;
|
||||
font-size: 10pt;
|
||||
margin-left: -50px;
|
||||
}
|
||||
.searchContainer button:hover,.searchContainer button:focus, .searchContainer button:active{
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#searchresult{
|
||||
}
|
||||
.resultwrapper{
|
||||
}
|
||||
button#closeSearchResult{
|
||||
position: absolute;
|
||||
right: 0px;
|
||||
top: 0px;
|
||||
margin: 10px;
|
||||
border: none;
|
||||
border-radius: 2px;
|
||||
font-size: 1rem;
|
||||
color: #fff;
|
||||
background: #000;
|
||||
padding: 15px;
|
||||
}
|
||||
button#closeSearchResult:hover,#closeSearchResult:focus{
|
||||
cursor: pointer;
|
||||
}
|
||||
.resultlist{
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
list-style:none;
|
||||
}
|
||||
.resultitem{
|
||||
|
||||
}
|
||||
.resultheader{
|
||||
|
||||
}
|
||||
.resultsnippet{
|
||||
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
var searchField = document.getElementById("searchField");
|
||||
var searchButton = document.getElementById("searchButton");
|
||||
|
||||
if(searchField && searchButton)
|
||||
{
|
||||
var searchIndex = false;
|
||||
var documents = false;
|
||||
var holdcontent = false;
|
||||
var contentwrapper = false;
|
||||
|
||||
searchField.addEventListener("focus", function(event){
|
||||
|
||||
if(!searchIndex)
|
||||
{
|
||||
myaxios.get('/indexrs51gfe2o2')
|
||||
.then(function (response) {
|
||||
|
||||
documents = JSON.parse(response.data);
|
||||
|
||||
searchIndex = lunr(function() {
|
||||
this.ref("id");
|
||||
this.field("title", { boost: 10 });
|
||||
this.field("content");
|
||||
for (var key in documents){
|
||||
this.add({
|
||||
"id": documents[key].url,
|
||||
"title": documents[key].title,
|
||||
"content": documents[key].content
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
.catch(function (error) {});
|
||||
}
|
||||
});
|
||||
|
||||
searchButton.addEventListener("click", function(event){
|
||||
event.preventDefault();
|
||||
|
||||
var term = document.getElementById('searchField').value;
|
||||
var results = searchIndex.search(term);
|
||||
|
||||
var resultPages = results.map(function (match) {
|
||||
return documents[match.ref];
|
||||
});
|
||||
|
||||
resultsString = "<div class='resultwrapper'><h1>Result for " + term + "</h1>";
|
||||
resultsString += "<button id='closeSearchResult'>close</button>";
|
||||
resultsString += "<ul class='resultlist'>";
|
||||
resultPages.forEach(function (r) {
|
||||
resultsString += "<li class='resultitem'>";
|
||||
resultsString += "<a class='resultheader' href='" + r.url + "?q=" + term + "'><h3>" + r.title + "</h3></a>";
|
||||
resultsString += "<div class='resultsnippet'>" + r.content.substring(0, 200) + " ...</div>";
|
||||
resultsString += "</li>"
|
||||
});
|
||||
resultsString += "</ul></div>";
|
||||
|
||||
if(!holdcontent)
|
||||
{
|
||||
contentwrapper = document.getElementById("searchresult").parentNode;
|
||||
holdcontent = contentwrapper.innerHTML;
|
||||
}
|
||||
|
||||
contentwrapper.innerHTML = resultsString;
|
||||
|
||||
document.getElementById("closeSearchResult").addEventListener("click", function(event){
|
||||
contentwrapper.innerHTML = holdcontent;
|
||||
});
|
||||
|
||||
}, false);
|
||||
}
|
||||
|
||||
/*
|
||||
var searchIndex = lunr(function() {
|
||||
this.ref("id");
|
||||
this.field("title", { boost: 10 });
|
||||
this.field("content");
|
||||
for (var key in window.pages) {
|
||||
this.add({
|
||||
"id": key,
|
||||
"title": pages[key].title,
|
||||
"content": pages[key].content
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function getQueryVariable(variable) {
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if (pair[0] === variable) {
|
||||
return decodeURIComponent(pair[1].replace(/\+/g, "%20"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var searchTerm = getQueryVariable("q");
|
||||
// creation of searchIndex from earlier example
|
||||
var results = searchIndex.search(searchTerm);
|
||||
var resultPages = results.map(function (match) {
|
||||
return pages[match.ref];
|
||||
});
|
||||
|
||||
// resultPages from previous example
|
||||
resultsString = "";
|
||||
resultPages.forEach(function (r) {
|
||||
resultsString += "<li>";
|
||||
resultsString += "<a class='result' href='" + r.url + "?q=" + searchTerm + "'><h3>" + r.title + "</h3></a>";
|
||||
resultsString += "<div class='snippet'>" + r.content.substring(0, 200) + "</div>";
|
||||
resultsString += "</li>"
|
||||
});
|
||||
document.querySelector("#search-results").innerHTML = resultsString;
|
||||
*/
|
|
@ -1,128 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Plugins\search;
|
||||
|
||||
use \Typemill\Plugin;
|
||||
use \Typemill\Models\Write;
|
||||
|
||||
class Search extends index
|
||||
{
|
||||
protected $item;
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
'onSettingsLoaded' => 'onsettingsLoaded',
|
||||
'onContentArrayLoaded' => 'onContentArrayLoaded',
|
||||
'onPageReady' => 'onPageReady',
|
||||
'onPagePublished' => 'onPagePublished',
|
||||
'onPageUnpublished' => 'onPageUnpublished',
|
||||
'onPageSorted' => 'onPageSorted',
|
||||
'onPageDeleted' => 'onPageDeleted',
|
||||
);
|
||||
}
|
||||
|
||||
# get search.json with route
|
||||
# update search.json on publish
|
||||
|
||||
public static function addNewRoutes()
|
||||
{
|
||||
# the route for the api calls
|
||||
return array(
|
||||
array(
|
||||
'httpMethod' => 'get',
|
||||
'route' => '/indexrs51gfe2o2',
|
||||
'class' => 'Plugins\search\index:index'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function onSettingsLoaded($settings)
|
||||
{
|
||||
$this->settings = $settings->getData();
|
||||
}
|
||||
|
||||
# at any of theses events, delete the old search index
|
||||
public function onPagePublished($item)
|
||||
{
|
||||
$this->deleteSearchIndex();
|
||||
}
|
||||
public function onPageUnpublished($item)
|
||||
{
|
||||
$this->deleteSearchIndex();
|
||||
}
|
||||
public function onPageSorted($inputParams)
|
||||
{
|
||||
$this->deleteSearchIndex();
|
||||
}
|
||||
public function onPageDeleted($item)
|
||||
{
|
||||
$this->deleteSearchIndex();
|
||||
}
|
||||
|
||||
private function deleteSearchIndex()
|
||||
{
|
||||
$write = new Write();
|
||||
|
||||
# store the index file here
|
||||
$write->deleteFileWithPath('cache' . DIRECTORY_SEPARATOR . 'index.json');
|
||||
}
|
||||
|
||||
public function onContentArrayLoaded($contentArray)
|
||||
{
|
||||
# get content array
|
||||
$content = $contentArray->getData();
|
||||
$settings = $this->getPluginSettings('search');
|
||||
$salt = "asPx9Derf2";
|
||||
|
||||
# activate axios and vue in frontend
|
||||
$this->activateAxios();
|
||||
$this->activateVue();
|
||||
|
||||
# add the css and vue application
|
||||
$this->addCSS('/search/public/search.css');
|
||||
$this->addJS('/search/public/lunr.min.js');
|
||||
$this->addJS('/search/public/search.js');
|
||||
|
||||
# simple security for first request
|
||||
$secret = time();
|
||||
$secret = substr($secret,0,-1);
|
||||
$secret = md5($secret . $salt);
|
||||
|
||||
# simple csrf protection with a session for long following requests
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$length = 32;
|
||||
$token = substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $length);
|
||||
$_SESSION['search'] = $token;
|
||||
$_SESSION['search-expire'] = time() + 1300; # 60 seconds * 30 minutes
|
||||
|
||||
# create div for vue app
|
||||
$search = '<div data-access="' . $secret . '" data-token="' . $token . '" id="searchresult"></div>';
|
||||
|
||||
# create content type
|
||||
$search = Array
|
||||
(
|
||||
'rawHtml' => $search,
|
||||
'allowRawHtmlInSafeMode' => true,
|
||||
'autobreak' => 1
|
||||
);
|
||||
|
||||
$content[] = $search;
|
||||
|
||||
$contentArray->setData($content);
|
||||
}
|
||||
|
||||
public function onPageReady($page)
|
||||
{
|
||||
$pageData = $page->getData($page);
|
||||
|
||||
$pageData['widgets']['search'] = '<div class="searchContainer" id="searchForm">'.
|
||||
'<input id="searchField" type="text" placeholder="search ..." />'.
|
||||
'<button id="searchButton" type="button">GO</button>'.
|
||||
'</div>';
|
||||
$page->setData($pageData);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
name: Search
|
||||
version: 1.0.0
|
||||
description: Add a search to your website with lunr.js.
|
||||
author: Trendschau
|
||||
homepage: https://typemill.net
|
||||
licence: MIT
|
||||
paypal: https://paypal.me/typemill
|
||||
amount: 10
|
Binary file not shown.
Loading…
Add table
Reference in a new issue