feed-and-misc #50

Merged
rodude123 merged 2 commits from feed-and-misc into master 2023-11-18 13:14:08 +00:00
11 changed files with 161 additions and 27 deletions
Showing only changes of commit 5b063afad3 - Show all commits

View File

@ -15,7 +15,8 @@
"rbdwllr/psr-jwt": "^2.0", "rbdwllr/psr-jwt": "^2.0",
"tuupola/slim-jwt-auth": "^3.6", "tuupola/slim-jwt-auth": "^3.6",
"ext-dom": "*", "ext-dom": "*",
"ext-libxml": "*" "ext-libxml": "*",
"donatello-za/rake-php-plus": "^1.0"
}, },
"repositories": [ "repositories": [
{ {

62
composer.lock generated
View File

@ -4,8 +4,68 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "bc139d99ef0f6c0f9868982d540fe1c5", "content-hash": "f675ad7eec6390b82dca0b13dec49e5b",
"packages": [ "packages": [
{
"name": "donatello-za/rake-php-plus",
"version": "v1.0.18",
"source": {
"type": "git",
"url": "https://github.com/Donatello-za/rake-php-plus.git",
"reference": "e9e9c0862b3dc953d288e8f42c76e4ceaeca0619"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Donatello-za/rake-php-plus/zipball/e9e9c0862b3dc953d288e8f42c76e4ceaeca0619",
"reference": "e9e9c0862b3dc953d288e8f42c76e4ceaeca0619",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=5.4.0"
},
"require-dev": {
"php": ">=5.5.0",
"phpunit/phpunit": "~4.0|~5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.13-dev"
}
},
"autoload": {
"psr-4": {
"DonatelloZa\\RakePlus\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Don Schoeman",
"email": "ta.maximus@gmail.com"
}
],
"description": "Yet another PHP implementation of the Rapid Automatic Keyword Extraction algorithm (RAKE).",
"homepage": "https://github.com/Donatello-za/rake-php-plus",
"keywords": [
"Algorithm",
"automatic",
"extraction",
"keyword",
"rake",
"rapid"
],
"support": {
"issues": "https://github.com/Donatello-za/rake-php-plus/issues",
"source": "https://github.com/Donatello-za/rake-php-plus"
},
"time": "2022-02-23T18:42:03+00:00"
},
{ {
"name": "fig/http-message-util", "name": "fig/http-message-util",
"version": "1.1.5", "version": "1.1.5",

View File

@ -7,10 +7,12 @@ use api\utils\imgUtils;
use DOMDocument; use DOMDocument;
use PDO; use PDO;
use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UploadedFileInterface;
use DonatelloZa\RakePlus\RakePlus;
use function DI\string; use function DI\string;
use const api\utils\feedGenerator\ATOM; use const api\utils\feedGenerator\ATOM;
use const api\utils\feedGenerator\RSS2; use const api\utils\feedGenerator\RSS2;
require_once __DIR__ . "/../utils/config.php"; require_once __DIR__ . "/../utils/config.php";
require_once __DIR__ . "/../utils/imgUtils.php"; require_once __DIR__ . "/../utils/imgUtils.php";
require_once __DIR__ . "/../utils/feedGenerator/FeedWriter.php"; require_once __DIR__ . "/../utils/feedGenerator/FeedWriter.php";
@ -30,7 +32,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog ORDER BY featured DESC, headerImg, body, bodyText, categories, keywords, folderID FROM blog ORDER BY featured DESC,
dateCreated DESC;"); dateCreated DESC;");
$stmt->execute(); $stmt->execute();
@ -55,7 +57,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog WHERE headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE
title = :title;"); title = :title;");
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->execute(); $stmt->execute();
@ -80,7 +82,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog ORDER BY headerImg, body, bodyText, categories, keywords, folderID FROM blog ORDER BY
dateCreated DESC LIMIT 1;"); dateCreated DESC LIMIT 1;");
$stmt->execute(); $stmt->execute();
@ -104,7 +106,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog WHERE featured = 1;"); headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE featured = 1;");
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
@ -225,7 +227,9 @@ class blogData
$from = "../blog/imgs/tmp/"; $from = "../blog/imgs/tmp/";
$newBody = $this->changeHTMLSrc($body, $to, $from); $newBody = $this->changeHTMLSrc($body, $to, $from);
$stmt = $conn->prepare("UPDATE blog SET title = :title, featured = :featured, abstract = :abstract, body = :body, bodyText = :bodyText, dateModified = :dateModified, categories = :categories WHERE ID = :ID;"); $keywords = implode(", ", RakePlus::create($bodyText)->keywords());
$stmt = $conn->prepare("UPDATE blog SET title = :title, featured = :featured, abstract = :abstract, body = :body, bodyText = :bodyText, dateModified = :dateModified, categories = :categories, keywords = :keywords WHERE ID = :ID;");
$stmt->bindParam(":ID", $ID); $stmt->bindParam(":ID", $ID);
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->bindParam(":featured", $featured); $stmt->bindParam(":featured", $featured);
@ -234,6 +238,7 @@ class blogData
$stmt->bindParam(":bodyText", $bodyText); $stmt->bindParam(":bodyText", $bodyText);
$stmt->bindParam(":dateModified", $dateModified); $stmt->bindParam(":dateModified", $dateModified);
$stmt->bindParam(":categories", $categories); $stmt->bindParam(":categories", $categories);
$stmt->bindParam(":keywords", $keywords);
return $stmt->execute(); return $stmt->execute();
} }
@ -282,8 +287,10 @@ class blogData
$stmtMainProject->execute(); $stmtMainProject->execute();
} }
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, folderID) $keywords = implode(", ", RakePlus::create($bodyText)->keywords());
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :folderID);");
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, keywords, folderID)
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :keywords, :folderID);");
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->bindParam(":dateCreated", $dateCreated); $stmt->bindParam(":dateCreated", $dateCreated);
$stmt->bindParam(":dateModified", $dateCreated); $stmt->bindParam(":dateModified", $dateCreated);
@ -294,6 +301,7 @@ class blogData
$stmt->bindParam(":body", $newBody); $stmt->bindParam(":body", $newBody);
$stmt->bindParam(":bodyText", $bodyText); $stmt->bindParam(":bodyText", $bodyText);
$stmt->bindParam(":categories", $categories); $stmt->bindParam(":categories", $categories);
$stmt->bindParam(":keywords", $keywords);
$stmt->bindParam(":folderID", $folderID); $stmt->bindParam(":folderID", $folderID);
if ($stmt->execute()) if ($stmt->execute())

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/css/main.css vendored

File diff suppressed because one or more lines are too long

View File

@ -7,10 +7,12 @@ use api\utils\imgUtils;
use DOMDocument; use DOMDocument;
use PDO; use PDO;
use Psr\Http\Message\UploadedFileInterface; use Psr\Http\Message\UploadedFileInterface;
use DonatelloZa\RakePlus\RakePlus;
use function DI\string; use function DI\string;
use const api\utils\feedGenerator\ATOM; use const api\utils\feedGenerator\ATOM;
use const api\utils\feedGenerator\RSS2; use const api\utils\feedGenerator\RSS2;
require_once __DIR__ . "/../utils/config.php"; require_once __DIR__ . "/../utils/config.php";
require_once __DIR__ . "/../utils/imgUtils.php"; require_once __DIR__ . "/../utils/imgUtils.php";
require_once __DIR__ . "/../utils/feedGenerator/FeedWriter.php"; require_once __DIR__ . "/../utils/feedGenerator/FeedWriter.php";
@ -30,7 +32,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog ORDER BY featured DESC, headerImg, body, bodyText, categories, keywords, folderID FROM blog ORDER BY featured DESC,
dateCreated DESC;"); dateCreated DESC;");
$stmt->execute(); $stmt->execute();
@ -55,7 +57,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog WHERE headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE
title = :title;"); title = :title;");
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->execute(); $stmt->execute();
@ -80,7 +82,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog ORDER BY headerImg, body, bodyText, categories, keywords, folderID FROM blog ORDER BY
dateCreated DESC LIMIT 1;"); dateCreated DESC LIMIT 1;");
$stmt->execute(); $stmt->execute();
@ -104,7 +106,7 @@ class blogData
$conn = dbConn(); $conn = dbConn();
$stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated, $stmt = $conn->prepare("SELECT ID, title, DATE_FORMAT(dateCreated, '%Y-%m-%dT%TZ') AS dateCreated,
DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract, DATE_FORMAT(dateModified, '%Y-%m-%dT%TZ') AS dateModified, featured, abstract,
headerImg, body, bodyText, categories, folderID FROM blog WHERE featured = 1;"); headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE featured = 1;");
$stmt->execute(); $stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC); $result = $stmt->fetch(PDO::FETCH_ASSOC);
@ -225,7 +227,9 @@ class blogData
$from = "../blog/imgs/tmp/"; $from = "../blog/imgs/tmp/";
$newBody = $this->changeHTMLSrc($body, $to, $from); $newBody = $this->changeHTMLSrc($body, $to, $from);
$stmt = $conn->prepare("UPDATE blog SET title = :title, featured = :featured, abstract = :abstract, body = :body, bodyText = :bodyText, dateModified = :dateModified, categories = :categories WHERE ID = :ID;"); $keywords = implode(", ", RakePlus::create($bodyText)->keywords());
$stmt = $conn->prepare("UPDATE blog SET title = :title, featured = :featured, abstract = :abstract, body = :body, bodyText = :bodyText, dateModified = :dateModified, categories = :categories, keywords = :keywords WHERE ID = :ID;");
$stmt->bindParam(":ID", $ID); $stmt->bindParam(":ID", $ID);
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->bindParam(":featured", $featured); $stmt->bindParam(":featured", $featured);
@ -234,6 +238,7 @@ class blogData
$stmt->bindParam(":bodyText", $bodyText); $stmt->bindParam(":bodyText", $bodyText);
$stmt->bindParam(":dateModified", $dateModified); $stmt->bindParam(":dateModified", $dateModified);
$stmt->bindParam(":categories", $categories); $stmt->bindParam(":categories", $categories);
$stmt->bindParam(":keywords", $keywords);
return $stmt->execute(); return $stmt->execute();
} }
@ -282,8 +287,10 @@ class blogData
$stmtMainProject->execute(); $stmtMainProject->execute();
} }
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, folderID) $keywords = implode(", ", RakePlus::create($bodyText)->keywords());
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :folderID);");
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, keywords, folderID)
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :keywords, :folderID);");
$stmt->bindParam(":title", $title); $stmt->bindParam(":title", $title);
$stmt->bindParam(":dateCreated", $dateCreated); $stmt->bindParam(":dateCreated", $dateCreated);
$stmt->bindParam(":dateModified", $dateCreated); $stmt->bindParam(":dateModified", $dateCreated);
@ -294,6 +301,7 @@ class blogData
$stmt->bindParam(":body", $newBody); $stmt->bindParam(":body", $newBody);
$stmt->bindParam(":bodyText", $bodyText); $stmt->bindParam(":bodyText", $bodyText);
$stmt->bindParam(":categories", $categories); $stmt->bindParam(":categories", $categories);
$stmt->bindParam(":keywords", $keywords);
$stmt->bindParam(":folderID", $folderID); $stmt->bindParam(":folderID", $folderID);
if ($stmt->execute()) if ($stmt->execute())

View File

@ -73,6 +73,10 @@ article {
padding: 0 2em; padding: 0 2em;
} }
article a {
padding: 0 1em;
}
article a::before, article a::before,
article a::after { article a::after {
visibility: hidden; visibility: hidden;
@ -81,7 +85,7 @@ article a::after {
} }
article a::before { article a::before {
content: '<'; content: ' <';
margin-left: -0.5em; margin-left: -0.5em;
} }
@ -158,6 +162,7 @@ div.feeds .icons {
justify-content: space-around; justify-content: space-around;
align-items: flex-start; align-items: flex-start;
gap: 0.5em; gap: 0.5em;
flex-wrap: wrap-reverse;
} }
div.feeds h2 { div.feeds h2 {

View File

@ -166,9 +166,6 @@
grid-row: 2; grid-row: 2;
} }
div.feeds .icons {
flex-wrap: wrap;
}
} }
@media screen and (max-width: 30em) { @media screen and (max-width: 30em) {

View File

@ -156,7 +156,7 @@ function createLargePost(post)
<h2>${post.title}</h2> <h2>${post.title}</h2>
<h3>Last updated: ${dateModifiedString} | ${categories}</h3> <h3>Last updated: ${dateModifiedString} | ${categories}</h3>
<p>${post.abstract}</p> <p>${post.abstract}</p>
<a href="/blog/post/${post.title}#disqus_thread" class="btn btnPrimary">See Post</a> <a href="/blog/post/${post.title}" class="btn btnPrimary">See Post</a>
`; `;
content.appendChild(postContent); content.appendChild(postContent);
outerContent.appendChild(content); outerContent.appendChild(content);
@ -384,6 +384,54 @@ async function createSideContent()
return sideContent; return sideContent;
} }
function createMetaTag(nameOrProperty, attribute, value)
{
let existingTag = document.querySelector(`meta[name="${nameOrProperty}"], meta[property="${nameOrProperty}"]`);
if (!existingTag)
{
// If the meta tag doesn't exist, create it
let newTag = document.createElement('meta');
newTag.setAttribute(nameOrProperty.includes('name') ? 'name' : 'property', nameOrProperty);
newTag.setAttribute(attribute, value);
document.head.appendChild(newTag);
return;
}
existingTag.setAttribute(attribute, value);
}
/**
* inserts the meta tags
* @param json - the json
*/
function insertMetaTags(json)
{
let metaDesc = document.querySelector('meta[name="description"]');
metaDesc.setAttribute('content', json.abstract);
// Twitter meta tags
createMetaTag('twitter:title', 'content', json.title);
createMetaTag('twitter:description', 'content', json.abstract);
createMetaTag('twitter:image', 'content', json.headerImg);
// Open Graph (Facebook) meta tags
createMetaTag('og:title', 'content', json.title);
createMetaTag('og:description', 'content', json.abstract);
createMetaTag('og:image', 'content', json.headerImg);
createMetaTag('og:url', 'content', window.location.href);
createMetaTag('og:type', 'content', 'blog');
createMetaTag('og:site_name', 'content', 'Rohit Pai\'s Blog');
createMetaTag('og:locale', 'content', 'en_GB');
//Keywords
let metKeywords = document.querySelector('meta[name="keywords"]');
let keywords = metKeywords.getAttribute('content');
keywords += `, ${json.keywords}`;
metKeywords.setAttribute('content', keywords);
}
/** /**
* Trys to load the individual post if not runs the 404 function * Trys to load the individual post if not runs the 404 function
* @param title * @param title
@ -401,6 +449,8 @@ async function loadIndividualPost(title)
await res.json().then(async json => await res.json().then(async json =>
{ {
//replace meta description
insertMetaTags(json);
// create the post // create the post
let post = document.createElement('section'); let post = document.createElement('section');
post.classList.add('post'); post.classList.add('post');
@ -413,7 +463,9 @@ async function loadIndividualPost(title)
<div class="byLine"> <div class="byLine">
<h3>Published: ${createFormattedDate(json.dateCreated)} | Last updated: ${createFormattedDate(json.dateModified)}</h3> <h3>Published: ${createFormattedDate(json.dateCreated)} | Last updated: ${createFormattedDate(json.dateModified)}</h3>
<h3>${createButtonCategories([csvToArray(json.categories.replace(/\s*,\s*/g, ','))])}</h3> <h3>${createButtonCategories([csvToArray(json.categories.replace(/\s*,\s*/g, ','))])}</h3>
<div class="sharethis-inline-share-buttons"></div> <div class="sharethis-inline-share-buttons" data-url="https://rohitpai.co.uk/blog/post/${title}"
data-title="${json.title}" data-description="${json.abstract}"
data-image="https://rohitpai.co.uk/${json.headerImg}" data-username="@rohitpai123"></div>
</div> </div>
<div class="cover" style="background-image: url('${json.headerImg}')"></div> <div class="cover" style="background-image: url('${json.headerImg}')"></div>
${json.body} ${json.body}

View File

@ -299,6 +299,9 @@ a {
text-transform: lowercase; text-transform: lowercase;
} }
a.link {
padding: 0 0.5em;
}
a.link::before, a.link::before,
a.link::after { a.link::after {
@ -308,12 +311,12 @@ a.link::after {
} }
a.link::before { a.link::before {
content: '<'; content: ' <';
margin-left: -0.5em; margin-left: -0.5em;
} }
a.link::after { a.link::after {
content: '>'; content: '> ';
} }
a.link:hover::before, a.link:hover::before,