Got keywords from text using rake-php-plus and then stored in the DB, then used it to append the keywords to the meta tag.
All checks were successful
🚀 Deploy website on push / 🎉 Deploy (push) Successful in 20s
All checks were successful
🚀 Deploy website on push / 🎉 Deploy (push) Successful in 20s
Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
parent
f27a5113b1
commit
5b063afad3
@ -15,7 +15,8 @@
|
||||
"rbdwllr/psr-jwt": "^2.0",
|
||||
"tuupola/slim-jwt-auth": "^3.6",
|
||||
"ext-dom": "*",
|
||||
"ext-libxml": "*"
|
||||
"ext-libxml": "*",
|
||||
"donatello-za/rake-php-plus": "^1.0"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
|
62
composer.lock
generated
62
composer.lock
generated
@ -4,9 +4,69 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "bc139d99ef0f6c0f9868982d540fe1c5",
|
||||
"content-hash": "f675ad7eec6390b82dca0b13dec49e5b",
|
||||
"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",
|
||||
"version": "1.1.5",
|
||||
"source": {
|
||||
|
22
dist/api/blog/blogData.php
vendored
22
dist/api/blog/blogData.php
vendored
@ -7,10 +7,12 @@ use api\utils\imgUtils;
|
||||
use DOMDocument;
|
||||
use PDO;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use DonatelloZa\RakePlus\RakePlus;
|
||||
use function DI\string;
|
||||
use const api\utils\feedGenerator\ATOM;
|
||||
use const api\utils\feedGenerator\RSS2;
|
||||
|
||||
|
||||
require_once __DIR__ . "/../utils/config.php";
|
||||
require_once __DIR__ . "/../utils/imgUtils.php";
|
||||
require_once __DIR__ . "/../utils/feedGenerator/FeedWriter.php";
|
||||
@ -30,7 +32,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
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;");
|
||||
$stmt->execute();
|
||||
|
||||
@ -55,7 +57,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
headerImg, body, bodyText, categories, folderID FROM blog WHERE
|
||||
headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE
|
||||
title = :title;");
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->execute();
|
||||
@ -80,7 +82,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
headerImg, body, bodyText, categories, folderID FROM blog ORDER BY
|
||||
headerImg, body, bodyText, categories, keywords, folderID FROM blog ORDER BY
|
||||
dateCreated DESC LIMIT 1;");
|
||||
$stmt->execute();
|
||||
|
||||
@ -104,7 +106,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
headerImg, body, bodyText, categories, folderID FROM blog WHERE featured = 1;");
|
||||
headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE featured = 1;");
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
@ -225,7 +227,9 @@ class blogData
|
||||
$from = "../blog/imgs/tmp/";
|
||||
$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(":title", $title);
|
||||
$stmt->bindParam(":featured", $featured);
|
||||
@ -234,6 +238,7 @@ class blogData
|
||||
$stmt->bindParam(":bodyText", $bodyText);
|
||||
$stmt->bindParam(":dateModified", $dateModified);
|
||||
$stmt->bindParam(":categories", $categories);
|
||||
$stmt->bindParam(":keywords", $keywords);
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
@ -282,8 +287,10 @@ class blogData
|
||||
$stmtMainProject->execute();
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, folderID)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :folderID);");
|
||||
$keywords = implode(", ", RakePlus::create($bodyText)->keywords());
|
||||
|
||||
$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(":dateCreated", $dateCreated);
|
||||
$stmt->bindParam(":dateModified", $dateCreated);
|
||||
@ -294,6 +301,7 @@ class blogData
|
||||
$stmt->bindParam(":body", $newBody);
|
||||
$stmt->bindParam(":bodyText", $bodyText);
|
||||
$stmt->bindParam(":categories", $categories);
|
||||
$stmt->bindParam(":keywords", $keywords);
|
||||
$stmt->bindParam(":folderID", $folderID);
|
||||
|
||||
if ($stmt->execute())
|
||||
|
2
dist/blog/css/main.css
vendored
2
dist/blog/css/main.css
vendored
File diff suppressed because one or more lines are too long
2
dist/blog/js/index.js
vendored
2
dist/blog/js/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/css/main.css
vendored
2
dist/css/main.css
vendored
File diff suppressed because one or more lines are too long
@ -7,10 +7,12 @@ use api\utils\imgUtils;
|
||||
use DOMDocument;
|
||||
use PDO;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use DonatelloZa\RakePlus\RakePlus;
|
||||
use function DI\string;
|
||||
use const api\utils\feedGenerator\ATOM;
|
||||
use const api\utils\feedGenerator\RSS2;
|
||||
|
||||
|
||||
require_once __DIR__ . "/../utils/config.php";
|
||||
require_once __DIR__ . "/../utils/imgUtils.php";
|
||||
require_once __DIR__ . "/../utils/feedGenerator/FeedWriter.php";
|
||||
@ -30,7 +32,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
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;");
|
||||
$stmt->execute();
|
||||
|
||||
@ -55,7 +57,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
headerImg, body, bodyText, categories, folderID FROM blog WHERE
|
||||
headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE
|
||||
title = :title;");
|
||||
$stmt->bindParam(":title", $title);
|
||||
$stmt->execute();
|
||||
@ -80,7 +82,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
headerImg, body, bodyText, categories, folderID FROM blog ORDER BY
|
||||
headerImg, body, bodyText, categories, keywords, folderID FROM blog ORDER BY
|
||||
dateCreated DESC LIMIT 1;");
|
||||
$stmt->execute();
|
||||
|
||||
@ -104,7 +106,7 @@ class blogData
|
||||
$conn = dbConn();
|
||||
$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,
|
||||
headerImg, body, bodyText, categories, folderID FROM blog WHERE featured = 1;");
|
||||
headerImg, body, bodyText, categories, keywords, folderID FROM blog WHERE featured = 1;");
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
@ -225,7 +227,9 @@ class blogData
|
||||
$from = "../blog/imgs/tmp/";
|
||||
$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(":title", $title);
|
||||
$stmt->bindParam(":featured", $featured);
|
||||
@ -234,6 +238,7 @@ class blogData
|
||||
$stmt->bindParam(":bodyText", $bodyText);
|
||||
$stmt->bindParam(":dateModified", $dateModified);
|
||||
$stmt->bindParam(":categories", $categories);
|
||||
$stmt->bindParam(":keywords", $keywords);
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
@ -282,8 +287,10 @@ class blogData
|
||||
$stmtMainProject->execute();
|
||||
}
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO blog (title, dateCreated, dateModified, featured, headerImg, abstract, body, bodyText, categories, folderID)
|
||||
VALUES (:title, :dateCreated, :dateModified, :featured, :headerImg, :abstract, :body, :bodyText, :categories, :folderID);");
|
||||
$keywords = implode(", ", RakePlus::create($bodyText)->keywords());
|
||||
|
||||
$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(":dateCreated", $dateCreated);
|
||||
$stmt->bindParam(":dateModified", $dateCreated);
|
||||
@ -294,6 +301,7 @@ class blogData
|
||||
$stmt->bindParam(":body", $newBody);
|
||||
$stmt->bindParam(":bodyText", $bodyText);
|
||||
$stmt->bindParam(":categories", $categories);
|
||||
$stmt->bindParam(":keywords", $keywords);
|
||||
$stmt->bindParam(":folderID", $folderID);
|
||||
|
||||
if ($stmt->execute())
|
||||
|
@ -73,6 +73,10 @@ article {
|
||||
padding: 0 2em;
|
||||
}
|
||||
|
||||
article a {
|
||||
padding: 0 1em;
|
||||
}
|
||||
|
||||
article a::before,
|
||||
article a::after {
|
||||
visibility: hidden;
|
||||
@ -81,7 +85,7 @@ article a::after {
|
||||
}
|
||||
|
||||
article a::before {
|
||||
content: '<';
|
||||
content: ' <';
|
||||
margin-left: -0.5em;
|
||||
}
|
||||
|
||||
@ -158,6 +162,7 @@ div.feeds .icons {
|
||||
justify-content: space-around;
|
||||
align-items: flex-start;
|
||||
gap: 0.5em;
|
||||
flex-wrap: wrap-reverse;
|
||||
}
|
||||
|
||||
div.feeds h2 {
|
||||
|
@ -166,9 +166,6 @@
|
||||
grid-row: 2;
|
||||
}
|
||||
|
||||
div.feeds .icons {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 30em) {
|
||||
|
@ -156,7 +156,7 @@ function createLargePost(post)
|
||||
<h2>${post.title}</h2>
|
||||
<h3>Last updated: ${dateModifiedString} | ${categories}</h3>
|
||||
<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);
|
||||
outerContent.appendChild(content);
|
||||
@ -384,6 +384,54 @@ async function createSideContent()
|
||||
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
|
||||
* @param title
|
||||
@ -401,6 +449,8 @@ async function loadIndividualPost(title)
|
||||
|
||||
await res.json().then(async json =>
|
||||
{
|
||||
//replace meta description
|
||||
insertMetaTags(json);
|
||||
// create the post
|
||||
let post = document.createElement('section');
|
||||
post.classList.add('post');
|
||||
@ -413,7 +463,9 @@ async function loadIndividualPost(title)
|
||||
<div class="byLine">
|
||||
<h3>Published: ${createFormattedDate(json.dateCreated)} | Last updated: ${createFormattedDate(json.dateModified)}</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 class="cover" style="background-image: url('${json.headerImg}')"></div>
|
||||
${json.body}
|
||||
|
@ -299,6 +299,9 @@ a {
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
a.link {
|
||||
padding: 0 0.5em;
|
||||
}
|
||||
|
||||
a.link::before,
|
||||
a.link::after {
|
||||
@ -308,12 +311,12 @@ a.link::after {
|
||||
}
|
||||
|
||||
a.link::before {
|
||||
content: '<';
|
||||
content: ' <';
|
||||
margin-left: -0.5em;
|
||||
}
|
||||
|
||||
a.link::after {
|
||||
content: '>';
|
||||
content: '> ';
|
||||
}
|
||||
|
||||
a.link:hover::before,
|
||||
|
Loading…
Reference in New Issue
Block a user