Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4049ff
commit badf618
Showing
12 changed files
with
2,106 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0, minimum-scale=1.0" | ||
/> | ||
{{#title}} | ||
<title>{{title}}</title> | ||
<meta property="og:title" content="{{title}}" /> | ||
{{/title}} {{^title}} | ||
<title>Idyll</title> | ||
<meta property="og:title" content="Idyll Project" /> | ||
{{/title}} | ||
<meta charset="utf-8" /> | ||
{{#favicon}} | ||
<link rel="shortcut icon" type="image/x-icon" href="{{favicon}}" /> | ||
{{/favicon}} {{#shareImageUrl}} | ||
<meta property="og:image" content="{{shareImageUrl}}" /> | ||
<meta name="twitter:image:src" content="{{shareImageUrl}}" /> | ||
<meta name="twitter:card" content="summary_large_image" /> | ||
{{/shareImageUrl}} {{#shareImageWidth}} | ||
<meta property="og:image:width" content="{{shareImageWidth}}" /> | ||
{{/shareImageWidth}} {{#shareImageHeight}} | ||
<meta property="og:image:height" content="{{shareImageHeight}}" /> | ||
{{/shareImageHeight}} | ||
<meta property="og:type" content="article" /> | ||
|
||
{{#description}} | ||
<meta property="og:description" content="{{description}}" /> | ||
<meta property="description" content="{{description}}" /> | ||
{{/description}} {{#url}} | ||
<meta property="og:url" content="{{url}}" /> | ||
{{/url}} {{#twitterHandle}} | ||
<meta property="twitter:creator" content="{{twitterHandle}}" /> | ||
{{/twitterHandle}} {{#usesTex}} | ||
<link | ||
rel="stylesheet" | ||
href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/katex.min.css" | ||
/> | ||
{{/usesTex}} {{#googleFontsUrl}} | ||
<link rel="stylesheet" href="{{googleFontsUrl}}" /> | ||
{{/googleFontsUrl}} | ||
|
||
<link rel="stylesheet" href="static/issue-01-theme.css" /> | ||
<link rel="stylesheet" href="static/idyll_styles.css" /> | ||
</head> | ||
<body> | ||
<div id="idyll-mount">{{{idyllContent}}}</div> | ||
<script src="static/idyll_index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
|
||
|
||
const Swup = require('swup').default; | ||
const swupMergeHeadPlugin = require('swup/plugins/swupMergeHeadPlugin'); | ||
// const Swup = require('swup').default; | ||
// const swupMergeHeadPlugin = require('../lib/swupMergeHeadPlugin'); | ||
|
||
|
||
console.log(swupMergeHeadPlugin); | ||
const options = { | ||
elements: ['#idyll-mount'], | ||
plugins: [ | ||
swupMergeHeadPlugin | ||
] | ||
} | ||
// console.log(swupMergeHeadPlugin); | ||
// const options = { | ||
// elements: ['#idyll-mount'] | ||
// } | ||
|
||
const swup = new Swup(options); | ||
// const swup = new Swup(options); | ||
// swup.usePlugin(swupMergeHeadPlugin, { runScripts: true }) | ||
|
||
|
||
// swup.on('swup:contentReplaced', function () { | ||
// console.log('head content replaced'); | ||
// }); | ||
// // swup.on('swup:contentReplaced', function () { | ||
// // console.log('head content replaced'); | ||
// // }); | ||
|
||
module.exports = swup; | ||
// module.exports = swup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: 'swupMergeHeadPlugin', | ||
options: { runScripts: false }, | ||
exec: function exec(options, swup, getHTMLfromCache) { | ||
|
||
console.log('adding event listener'); | ||
document.addEventListener('swup:willReplaceContent', function () { | ||
console.log('on content replaced'); | ||
var currentHead = document.querySelector('head'); | ||
var newHead = getHTMLfromCache().querySelector('head'); | ||
replaceHeadWithoutReplacingExistingTags(currentHead, newHead); | ||
}); | ||
|
||
var replaceHeadWithoutReplacingExistingTags = function replaceHeadWithoutReplacingExistingTags(currentHead, newHead) { | ||
console.log('replacing head scripts'); | ||
var oldTags = currentHead.children; | ||
var newTags = newHead.children; | ||
var oldTagsToRemove = []; | ||
var newTagsToRemove = []; | ||
|
||
console.log('newHead', newHead); | ||
|
||
for (var i = 0; i < oldTags.length; i++) { | ||
var oldTag = oldTags[i]; | ||
var oldTagIdentifier = oldTag.outerHTML; | ||
var foundInNewHead = false; | ||
var newTag = void 0; | ||
for (var j = 0; j < newTags.length; j++) { | ||
newTag = newTags[j]; | ||
var newTagIdentifier = newTag.outerHTML; | ||
|
||
if (newTagIdentifier === oldTagIdentifier) { | ||
foundInNewHead = true; | ||
break; | ||
} | ||
} | ||
|
||
if (foundInNewHead) { | ||
console.log('not inserting ', newTag); | ||
newTagsToRemove.push(newTag); | ||
} else { | ||
console.log('old tag to remove ', oldTag); | ||
oldTagsToRemove.push(oldTag); | ||
} | ||
} | ||
|
||
for (var _i = 0; _i < newTagsToRemove.length; _i++) { | ||
newHead.removeChild(newTagsToRemove[_i]); | ||
} | ||
|
||
for (var _i2 = 0; _i2 < oldTagsToRemove.length; _i2++) { | ||
currentHead.removeChild(oldTagsToRemove[_i2]); | ||
} | ||
|
||
var added = newHead.children.length; | ||
var removed = oldTagsToRemove.length; | ||
console.log('added', added); | ||
console.log(newHead.children); | ||
|
||
var fragment = document.createDocumentFragment(); | ||
for (var _i3 = 0; _i3 < newHead.children.length; _i3++) { | ||
console.log('adding', newHead.children[_i3]); | ||
fragment.appendChild(newHead.children[_i3].cloneNode(true)); | ||
// fragment.appendChild(newHead.children[_i3]); | ||
} | ||
// console.log(fragment); | ||
currentHead.appendChild(fragment); | ||
|
||
if (options.runScripts) { | ||
newHead.querySelectorAll('script').forEach(function (item) { | ||
if (item.tagName == "SCRIPT" && (item.type == null || item.type == "" || item.type == "text/javascript")) { | ||
var elem = document.createElement('script'); | ||
if (item.src != null && item.src != "") { | ||
elem.src = item.src; | ||
} else { | ||
var inline = document.createTextNode(item.innerText); | ||
elem.appendChild(inline); | ||
} | ||
if (item.type != null && item.type != "") { | ||
elem.type = item.type; | ||
} | ||
currentHead.appendChild(elem); | ||
} else {} | ||
}); | ||
} | ||
|
||
console.log('Removed ' + removed + ' / added ' + added + ' tags in head'); | ||
swup.log('Removed ' + removed + ' / added ' + added + ' tags in head'); | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.