Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from brandonbk/inject-before-headline
Browse files Browse the repository at this point in the history
Inject ads before headlines
  • Loading branch information
zarathustra323 authored Mar 11, 2021
2 parents ece6e0d + de67861 commit 23cffa8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/marko-web-gam/browser/inject-ads.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
},
detectEmbeds: {
type: Boolean,
default: false,
default: true,
},
},
Expand Down Expand Up @@ -62,12 +62,15 @@ export default {
if (contents) {
// Unescape closing HTML tags.
const cleaned = contents.replace(/<\\\/(.+?)>/g, '</$1>');
const headlineTags = 'h1,h2,h3,h4,h5,h6';
if ($nextChild.text().length <= 1) {
// eslint-disable-next-line consistent-return
$child.nextAll(childSelector).each(function handleBefore() {
if ($(this).text().length > 1) {
const $previous = $(this).prev();
if (component.detectEmbeds && $previous.attr('data-embed-type')) {
if ($previous.is(headlineTags)) {
$previous.before(cleaned);
} else if ($previous.attr('data-embed-type')) {
$(this).after(cleaned);
} else {
$(this).before(cleaned);
Expand All @@ -77,7 +80,13 @@ export default {
});
} else {
const $next = $(this).next();
if (component.detectEmbeds && $next.attr('data-embed-type')) {
if ($next.attr('data-embed-type')) {
if ($child.prev().is(headlineTags)) {
$child.prev().before(cleaned);
} else {
$child.before(cleaned);
}
} else if ($child.is(headlineTags)) {
$child.before(cleaned);
} else {
$child.after(cleaned);
Expand Down

0 comments on commit 23cffa8

Please sign in to comment.