Skip to content

Commit

Permalink
Merge branch 'main' into blog-import
Browse files Browse the repository at this point in the history
  • Loading branch information
fe-lix- committed Nov 23, 2023
2 parents 3e0c0d9 + d8657df commit 95916a4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 32 deletions.
43 changes: 43 additions & 0 deletions helix-query.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
version: 1
indices:
blog_us:
include:
- /blog/**
target: /blog/query-index.json
properties:
lastModified:
select: none
value: parseTimestamp(headers["last-modified"], "ddd, DD MMM YYYY hh:mm:ss GMT")
date:
select: head > meta[name="publication-date"]
value: parseTimestamp(attribute(el, "content"), "MM/DD/YYYY")
title:
select: head > meta[property="og:title"]
value: attribute(el, "content")
description:
select: head > meta[property="og:description"]
value: attribute(el, "content")
image:
select: head > meta[property="og:image"]
value: attribute(el, "content")
blog_ca:
include:
- /ca/blog/**
target: /ca/blog/query-index.json
properties:
lastModified:
select: none
value: parseTimestamp(headers["last-modified"], "ddd, DD MMM YYYY hh:mm:ss GMT")
date:
select: head > meta[name="publication-date"]
value: parseTimestamp(attribute(el, "content"), "MM/DD/YYYY")
title:
select: head > meta[property="og:title"]
value: attribute(el, "content")
description:
select: head > meta[property="og:description"]
value: attribute(el, "content")
image:
select: head > meta[property="og:image"]
value: attribute(el, "content")
3 changes: 2 additions & 1 deletion tools/importer/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export default {
'div.cmp-page__skiptomaincontent',
'div#mainContent',
'div.page-header',
// Remove navigation from the beginning of blog entries as well as readmore-type teasers and blurb about 24petwatch at the end
// Remove navigation from the beginning of blog entries as well as readmore-type
// teasers and blurb about 24petwatch at the end
'nav',
'div.imagelist',
'div.cmp-experiencefragment--blog-page-cta-component',
Expand Down
35 changes: 13 additions & 22 deletions tools/importer/transformers/blogBanner.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
function blogBanner(main, document) {

// Banner image is in mainContent element
const bannerImage = main.querySelector('#mainContent img');

if( bannerImage ){

// Create div to hold image
const div = document.createElement('div');
const img = document.createElement('img');
const imgSrc = bannerImage.getAttribute('src');
img.setAttribute('src', imgSrc);
div.append(img);

main.prepend(div);

}

// const p = document.createElement('p');
// p.textContent = 'Hello world!';
// main.append(p);


// Banner image is in mainContent element
const bannerImage = main.querySelector('#mainContent img');

if (bannerImage) {
// Create div to hold image
const div = document.createElement('div');
const img = document.createElement('img');
const imgSrc = bannerImage.getAttribute('src');
img.setAttribute('src', imgSrc);
div.append(img);

main.prepend(div);
}
}

export default blogBanner;
4 changes: 2 additions & 2 deletions tools/importer/transformers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import createFooter from './footer.js';
import createFullLayoutSection from './fullLayoutSection.js';
import createHomepage from './homepage.js';
import createHeader from './header.js';
import createHero from './hero.js';
// import createHero from './hero.js';
import createMetadata from './metadata.js';
import createBold from './bold.js';
import blogBanner from './blogBanner.js';
Expand Down Expand Up @@ -36,5 +36,5 @@ export const preTransformers = [

export const postTransformers = [
createMetadata,
cleanBlog
cleanBlog,
];
15 changes: 8 additions & 7 deletions tools/importer/transformers/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,28 @@ const createMetadata = (main, document) => {

// Get blog article tags
const blogTags = document.querySelectorAll('div.cmp-contentfragment__element--tag > dd.cmp-contentfragment__element-value');
if( blogTags ) {
for( let i = 0; i < blogTags.length; i += 1 ) {
if (blogTags) {
for (let i = 0; i < blogTags.length; i += 1) {
meta.Tags = blogTags[i].innerHTML.trim()
.replaceAll('24petwatch:newletter/topic/','',)
.replaceAll('24petwatch:newletter/topic/', '')
.replaceAll('<br>', ',');
}
}

// Get blog related articles
// Assumes that related articles are rendered as the only ul on the page, if not, related articles are borked for the page
// Assumes that related articles are rendered as the only ul on the page,
// if not, related articles are borked for the page
const relatedArticles = document.querySelector('ul.cmp-image-list__list');
if ( relatedArticles ){
if (relatedArticles) {
const articleLinks = relatedArticles.querySelectorAll('a.cmp-image-list__item-title-link');
for ( let i = 0; i < articleLinks.length; i += 0 ) {
for (let i = 0; i < articleLinks.length; i += 0) {
meta.Related = articleLinks[i].getAttribute('href');
}
}

const author = document.querySelector('div.cmp-contentfragment__element--byline dd');
if (author) {
meta.Author = author.textContent.trim().replace(/^By /, '');
meta.Author = author.textContent.trim().replace(/^By /, '');
}

const block = WebImporter.Blocks.getMetadataBlock(document, meta);
Expand Down

0 comments on commit 95916a4

Please sign in to comment.