Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rsnyder committed Sep 7, 2024
1 parent cfa3bd5 commit 62ee92c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
9 changes: 8 additions & 1 deletion ghp-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,13 @@ function isJunctureV1(contentEl) {
return contentEl.querySelector('param[ve-config]') ? true : false
}

function getContent() {
console.log('getContent')
console.log('config.content', window.config.content)
console.log('document.body.children[0].innerHTML', document.body.children[0].innerHTML)
return window.config.content || document.body.children[0].innerHTML
}

// set the configuration
function setConfig() {
window.config = {
Expand Down Expand Up @@ -1084,7 +1091,7 @@ function articleFromHtml(html) {

// mount the content
function mount(mountPoint, html) {
html = html || window.config.content || document.body.innerHTML
html = html || getContent()
mountPoint = mountPoint || document.querySelector('body > article, body > main, body > section')
if (!mountPoint) {
mountPoint = document.createElement('article')
Expand Down
2 changes: 1 addition & 1 deletion wb/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

let easyMDE

console.log('referrer:', referrer.hostname )
// console.log('referrer:', referrer.hostname )
if (!sourceArg && referrer?.hostname === 'github.com') {
// redirect to editor with source query if referrer is a markdown file
let [acct, repo, branch, ...path] = referrer.pathname.split('/').filter(pe => pe && pe !== 'blob' && pe !== 'tree')
Expand Down
24 changes: 14 additions & 10 deletions wc/dist/js/ghp-lib.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// 1

import { marked } from "https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js";
import 'https://cdn.jsdelivr.net/npm/marked-footnote/dist/index.umd.min.js'
import * as yaml from 'https://cdn.jsdelivr.net/npm/[email protected]/browser/index.min.js'
Expand All @@ -15,14 +13,14 @@ const isMobile = ('ontouchstart' in document.documentElement && /mobi/i.test(nav
window.customEntityData = {}

function addLink(attrs) {
console.log('addLink', attrs)
// console.log('addLink', attrs)
let stylesheet = document.createElement('link')
Object.entries(attrs).map(([key, value]) => stylesheet.setAttribute(key, value))
document.head.appendChild(stylesheet)
}

function addScript(attrs) {
console.log('addScript', attrs)
// console.log('addScript', attrs)
let script = document.createElement('script')
Object.entries(attrs).map(([key, value]) => script.setAttribute(key, value))
document.head.appendChild(script)
Expand Down Expand Up @@ -514,10 +512,10 @@ function restructure(rootEl) {
} else {
header = main.querySelector('ve-header')
if (header) {
let toRemove = header
while (toRemove.parentElement.tagName !== 'MAIN') toRemove = toRemove.parentElement
// let toRemove = header
// while (toRemove.parentElement.tagName !== 'MAIN') toRemove = toRemove.parentElement
article.appendChild(header)
toRemove.remove()
// toRemove.remove()
}
}

Expand Down Expand Up @@ -988,9 +986,15 @@ function isJunctureV1(contentEl) {
return contentEl.querySelector('param[ve-config]') ? true : false
}

function getContent() {
console.log('getContent')
console.log('config.content', window.config.content)
console.log('document.body.children[0].innerHTML', document.body.children[0].innerHTML)
return window.config.content || document.body.children[0].innerHTML
}

// set the configuration
function setConfig() {
console.log('setConfig', window.jekyll)
window.config = {
...yaml.parse(window.options || ''),
...(window.jekyll || {}),
Expand All @@ -1011,7 +1015,7 @@ function setConfig() {
let contentEl = document.createElement('main')
contentEl.innerHTML = window.config.content || document.body.innerHTML
window.config.isJunctureV1 = isJunctureV1(contentEl)
console.log(window.config)
// console.log(window.config)
}

function readMoreSetup() {
Expand Down Expand Up @@ -1087,7 +1091,7 @@ function articleFromHtml(html) {

// mount the content
function mount(mountPoint, html) {
html = html || window.config.content || document.body.innerHTML
html = html || getContent()
mountPoint = mountPoint || document.querySelector('body > article, body > main, body > section')
if (!mountPoint) {
mountPoint = document.createElement('article')
Expand Down
4 changes: 1 addition & 3 deletions wc/dist/js/ghp.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// 1

import { addLink, addScript, articleFromHtml, getGhFile, getMarkdown, markdownToHtml, mode, mount, setConfig, structureContent } from './ghp-lib.js'

const base = mode === 'prod'
? import.meta.url.replace(/\/js\/ghp\.js$/, '')
: import.meta.url.replace(/\/ghp\.js$/, '/wc/dist')

console.log(`mode=${mode} base=${base}`)
// console.log(`mode=${mode} base=${base}`)

if (!window.config) setConfig()

Expand Down
2 changes: 1 addition & 1 deletion wc/dist/js/index.js

Large diffs are not rendered by default.

0 comments on commit 62ee92c

Please sign in to comment.