Skip to content

Commit 3867956

Browse files
authored
Merge pull request #155 from canopas/fix-tags-and-pupeeter-issue
Fix: tags and pupeeter issue
2 parents 3c7e778 + 42e5cd2 commit 3867956

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

admin/src/api/post/content-types/post/lifecycles.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@ module.exports = {
1717
},
1818

1919
async afterUpdate(event) {
20-
console.log(
21-
"afterUpdate: ",
22-
event.params.data.publishedAt,
23-
event.result.is_published
24-
);
2520
if (event.params.data.publishedAt) {
2621
if (!event.result.is_published) {
27-
console.log("afterUpdate inside: ", event.result.is_published);
2822
await strapi.db.query("api::post.post").update({
2923
where: { id: event.result.id },
3024
data: {
@@ -125,19 +119,19 @@ function generateSlug(title, slug) {
125119
async function TagsInput(tags) {
126120
let tagsData = [];
127121
for (i = 0; i < tags.length; i++) {
122+
let slug = tags[i].name
123+
.replace(/\s/g, "-")
124+
.replace(/[^A-Za-z-]/g, "")
125+
.toLowerCase();
126+
128127
let existingTag = await strapi.db.query("api::tag.tag").findOne({
129-
where: {
130-
name: {
131-
$eqi: tags[i].name,
132-
},
133-
},
128+
where: { slug },
134129
});
135130

136-
if (existingTag == null) {
137-
let slug = tags[i].name
138-
.replace(/\s/g, "-")
139-
.replace(/[^A-Za-z-]/g, "")
140-
.toLowerCase();
131+
const insert = existingTag && existingTag.name != tags[i].name;
132+
slug = insert ? slug + "-" + i : slug;
133+
134+
if (existingTag == null || insert) {
141135
existingTag = await strapi.db.query("api::tag.tag").create({
142136
data: {
143137
slug,
@@ -333,7 +327,7 @@ async function runScraper(url) {
333327
});
334328
try {
335329
const page = await browser.newPage();
336-
await page.goto(url);
330+
await page.goto(url, { waitUntil: "domcontentloaded" });
337331
const obj = {
338332
title: await getTitle(page),
339333
description: await getDescription(page),

0 commit comments

Comments
 (0)