change: store note files with .md extension
This commit is contained in:
parent
40c90d07bc
commit
b6c1d965c8
22
index.php
22
index.php
|
@ -29,7 +29,7 @@
|
||||||
{
|
{
|
||||||
return filemtime($b) - filemtime($a);
|
return filemtime($b) - filemtime($a);
|
||||||
});
|
});
|
||||||
$_SESSION['index'] = $files;
|
$_SESSION['index'] = array_map(fn($value): string => str_replace('.md', '', $value), $files);
|
||||||
}
|
}
|
||||||
|
|
||||||
function removefromindex($title)
|
function removefromindex($title)
|
||||||
|
@ -50,16 +50,16 @@
|
||||||
$previous = $_POST['lastchanged'];
|
$previous = $_POST['lastchanged'];
|
||||||
if (!isset($_GET['clip']) && (int)$lastchanged > (int)$previous)
|
if (!isset($_GET['clip']) && (int)$lastchanged > (int)$previous)
|
||||||
{
|
{
|
||||||
$tempcontent = file_get_contents($path);
|
$tempcontent = file_get_contents($path . '.md');
|
||||||
if ($tempcontent != $content)
|
if ($tempcontent != $content)
|
||||||
{
|
{
|
||||||
$temptitle = $title . '_' . $lastchanged;
|
$temptitle = $title . '_' . $lastchanged;
|
||||||
file_put_contents($dir . '/' . $temptitle, $tempcontent);
|
file_put_contents($dir . '/' . $temptitle . '.md', $tempcontent);
|
||||||
array_unshift($_SESSION['index'], $dir . '/' . $temptitle);
|
array_unshift($_SESSION['index'], $dir . '/' . $temptitle);
|
||||||
echo '<div class="grey">Conflict detected. See backup: ' . $temptitle . '</div>';
|
echo '<div class="grey">Conflict detected. See backup: ' . $temptitle . '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file_put_contents($path, $content);
|
file_put_contents($path . '.md', $content);
|
||||||
removefromindex($title);
|
removefromindex($title);
|
||||||
array_unshift($_SESSION['index'], $path);
|
array_unshift($_SESSION['index'], $path);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@
|
||||||
|
|
||||||
if (isset($_GET['clip']) && $_GET['param'])
|
if (isset($_GET['clip']) && $_GET['param'])
|
||||||
{
|
{
|
||||||
$content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo');
|
$content = $_GET['param'] . "\r\n" . file_get_contents($dir . '/todo.md');
|
||||||
savenote('todo', $content);
|
savenote('todo', $content);
|
||||||
$_GET['param'] = '';
|
$_GET['param'] = '';
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
$previoustitle = $_POST['previoustitle'];
|
$previoustitle = $_POST['previoustitle'];
|
||||||
if ($title != $previoustitle)
|
if ($title != $previoustitle)
|
||||||
{
|
{
|
||||||
rename($dir . '/' . $previoustitle, $dir . '/' . $previoustitle . '.del');
|
rename($dir . '/' . $previoustitle . '.md', $dir . '/' . $previoustitle . '.md.del');
|
||||||
removefromindex($previoustitle);
|
removefromindex($previoustitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@
|
||||||
else if (isset($_POST['delete']))
|
else if (isset($_POST['delete']))
|
||||||
{
|
{
|
||||||
$title = $_POST['title'];
|
$title = $_POST['title'];
|
||||||
rename($dir . '/' . $title, $dir . '/' . $title . '.del');
|
rename($dir . '/' . $title . '.md', $dir . '/' . $title . '.md.del');
|
||||||
removefromindex($title);
|
removefromindex($title);
|
||||||
}
|
}
|
||||||
else if (isset($_POST['preview']))
|
else if (isset($_POST['preview']))
|
||||||
|
@ -152,18 +152,18 @@
|
||||||
$title = $now;
|
$title = $now;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_exists($dir . '/' . $title))
|
if (!file_exists($dir . '/' . $title . '.md'))
|
||||||
{
|
{
|
||||||
$content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n";
|
$content = "---\r\ndate: " . substr($now, 0, 10) . "\r\ntags: \r\n---\r\n";
|
||||||
savenote($title, $content);
|
savenote($title, $content);
|
||||||
}
|
}
|
||||||
else if (!$content)
|
else if (!$content)
|
||||||
{
|
{
|
||||||
$content = file_get_contents($dir . '/' . $title);
|
$content = file_get_contents($dir . '/' . $title . '.md');
|
||||||
}
|
}
|
||||||
|
|
||||||
clearstatcache();
|
clearstatcache();
|
||||||
$lastchanged = filemtime($dir . '/' . $title);
|
$lastchanged = filemtime($dir . '/' . $title . '.md');
|
||||||
$lines = substr_count($content, "\r\n");
|
$lines = substr_count($content, "\r\n");
|
||||||
$words = substr_count($content, " ") + $lines;
|
$words = substr_count($content, " ") + $lines;
|
||||||
$chars = strlen($content);
|
$chars = strlen($content);
|
||||||
|
@ -191,7 +191,7 @@
|
||||||
{
|
{
|
||||||
if (($_GET['param'] && isset($_GET['search'])) || isset($_GET['tags']))
|
if (($_GET['param'] && isset($_GET['search'])) || isset($_GET['tags']))
|
||||||
{
|
{
|
||||||
$content = file_get_contents($path);
|
$content = file_get_contents($path . '.md');
|
||||||
|
|
||||||
if ((isset($_GET['search']) && !str_contains(strtolower($content), strtolower($param)) && !str_contains(strtolower($name), strtolower($param)))
|
if ((isset($_GET['search']) && !str_contains(strtolower($content), strtolower($param)) && !str_contains(strtolower($name), strtolower($param)))
|
||||||
|| (isset($_GET['tags']) && !preg_match('/tags:.*' . $param . '/i', $content)))
|
|| (isset($_GET['tags']) && !preg_match('/tags:.*' . $param . '/i', $content)))
|
||||||
|
|
Loading…
Reference in New Issue