Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: tags and pupeeter issue #155

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions admin/src/api/post/content-types/post/lifecycles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ module.exports = {
},

async afterUpdate(event) {
console.log(
"afterUpdate: ",
event.params.data.publishedAt,
event.result.is_published
);
if (event.params.data.publishedAt) {
if (!event.result.is_published) {
console.log("afterUpdate inside: ", event.result.is_published);
await strapi.db.query("api::post.post").update({
where: { id: event.result.id },
data: {
Expand Down Expand Up @@ -125,19 +119,19 @@ function generateSlug(title, slug) {
async function TagsInput(tags) {
let tagsData = [];
for (i = 0; i < tags.length; i++) {
let slug = tags[i].name
.replace(/\s/g, "-")
.replace(/[^A-Za-z-]/g, "")
.toLowerCase();

let existingTag = await strapi.db.query("api::tag.tag").findOne({
where: {
name: {
$eqi: tags[i].name,
},
},
where: { slug },
});

if (existingTag == null) {
let slug = tags[i].name
.replace(/\s/g, "-")
.replace(/[^A-Za-z-]/g, "")
.toLowerCase();
const insert = existingTag && existingTag.name != tags[i].name;
slug = insert ? slug + "-" + i : slug;

if (existingTag == null || insert) {
existingTag = await strapi.db.query("api::tag.tag").create({
data: {
slug,
Expand Down Expand Up @@ -333,7 +327,7 @@ async function runScraper(url) {
});
try {
const page = await browser.newPage();
await page.goto(url);
await page.goto(url, { waitUntil: "domcontentloaded" });
const obj = {
title: await getTitle(page),
description: await getDescription(page),
Expand Down
Loading