-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new content for 2025-01-16 and update redirection in index.html
- Loading branch information
1 parent
715095b
commit d0f6f58
Showing
9 changed files
with
911 additions
and
1 deletion.
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,15 @@ | ||
# Read Me | ||
|
||
* https://heritage-happenings.github.io/code/gfo/github-file-open.html | ||
|
||
|
||
## To Do / Wish List | ||
|
||
* 2025-01-14 ~ set default file & path content viw function calls | ||
|
||
|
||
## Change log | ||
|
||
### 2025-01-14 | ||
|
||
* Clean up |
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,49 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>Open Index or Markdown</title> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=contain"> | ||
<meta name="description" content="File wrangler: Opens HTML or Markdown files. Passes location.hash."> | ||
<meta name="keywords" content="ShowDown,Markdown,AJAX,JavaScript,HTML,CSS,GitHub,FOSS"> | ||
<meta name="version" content="2025-01-15"> | ||
<meta name="author" content="Theo Armour"> | ||
<meta name="creator" content="https://github.com/pushme-pullyou/tootoo-2025"> | ||
|
||
<link rel="stylesheet" href="../style.css"> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<!-- https://github.com/showdownjs/showdown --> | ||
<!-- https://showdownjs.com/docs/available-options/ --> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/2.1.0/showdown.min.js"></script> | ||
|
||
<div id=divMainContent></div> | ||
|
||
<script> | ||
|
||
COR = { | ||
|
||
defaultFile: "HOME.md", | ||
pathContent: "../../../", | ||
|
||
}; | ||
|
||
</script> | ||
|
||
<script src="github-file-open.js"></script> | ||
|
||
<script> | ||
|
||
GFO.onHashChange(); | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const GFO = ( function () { | ||
|
||
const defaultFile = COR.defaultFile; | ||
|
||
// Set the flavor of the Markdown converter | ||
showdown.setFlavor( "github" ); | ||
|
||
// Set the options for the Markdown converter | ||
const options = { | ||
backslashEscapesHTMLTags: true, | ||
completeHTMLDocument: false, | ||
disableForced4SpacesIndentedSublists: true, | ||
emoji: true, | ||
excludeTrailingPunctuationFromURLs: true, | ||
ghMention: true, | ||
noHeaderId: true, | ||
openLinksInNewWindow: false, | ||
simplifiedAutoLink: true, | ||
simpleLineBreaks: true, | ||
smoothLivePreview: true, | ||
strikethrough: true, | ||
tasklists: true, | ||
}; | ||
|
||
// Listen for changes to the hash in the URL | ||
window.addEventListener( "hashchange", onHashChange, false ); | ||
|
||
// If there's no hash in the URL, set it to the default file | ||
if ( !location.hash ) { | ||
|
||
location.hash = defaultFile; | ||
|
||
} else { | ||
|
||
//onHashChange(); | ||
|
||
} | ||
|
||
function onHashChange () { | ||
|
||
// Get the URL from the hash and update the document title | ||
const url = location.hash.slice( 1 ); | ||
|
||
setDocumentTitle( url ); | ||
|
||
// Fetch the file and update the page content | ||
fetchFile( COR.pathContent + url, options ); | ||
|
||
} | ||
|
||
function setDocumentTitle ( url ) { | ||
|
||
const title = url.split( "/" ).pop() | ||
.split( "-" ) | ||
.filter( word => word.length > 0 ) | ||
.map( word => word.charAt( 0 ).toUpperCase() + word.slice( 1 ) ) | ||
.join( " " ); | ||
|
||
document.title = title; | ||
|
||
} | ||
|
||
function fetchFile ( url, options ) { | ||
|
||
fetch( url ) | ||
.then( response => response.text() ) | ||
.then( txt => { | ||
|
||
const extension = url.includes( "." ) ? url.toLowerCase().split( '.' ).pop() : ""; | ||
//console.log( "extension", extension ); | ||
|
||
if ( [ "", "LICENSE", "txt", "md", "markdown" ].includes( extension ) ) { | ||
|
||
txt = txt.replace( /\<!--@@@/, "" ).replace( /\@@@--\>/, "" ); | ||
divMainContent.innerHTML = new showdown.Converter( options ).makeHtml( txt ); | ||
|
||
} else if ( [ "gif", "jpg", "jpeg", "png", "svg" ].includes( extension ) ) { | ||
|
||
divMainContent.innerHTML = `<img src="${ url }" style="border:none;max-width:100%;" >`; | ||
|
||
} else { | ||
|
||
divMainContent.innerHTML = `<iframe src="${ url }" height=${ window.innerHeight } style="border:none;width:100%;" ></iframe>`; | ||
|
||
} | ||
|
||
window.scrollTo( 0, 0 ); | ||
|
||
} ) | ||
.catch( err => console.error( "Error fetching file:", err ) ); | ||
} | ||
|
||
return { | ||
onHashChange, | ||
setDocumentTitle, | ||
fetchFile | ||
}; | ||
} )(); | ||
|
||
test = function () { | ||
console.log( "test" ); | ||
location.hash = "test.md"; | ||
}; |
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,29 @@ | ||
<!doctype html> | ||
<html lang=en> | ||
|
||
<head> | ||
<title>gfv</title> | ||
<meta charset=utf-8 /> | ||
</head> | ||
|
||
<body style="font: 100% monospace;"> | ||
<script> | ||
|
||
COR = { | ||
|
||
user: "heritage-happenings", | ||
repo: "heritage-happenings.github.io", | ||
branch: "master", | ||
filterFolders: ["food-service", "happenings-issues","histories","pages","photos", "scans"], | ||
ignoreFiles: ["404.html", "favicon.ico", "index.html", "LICENSE", "readme.html", "test.md"], | ||
|
||
} | ||
</script> | ||
|
||
<script src="./github-tree-view.js"></script> | ||
|
||
<div id="divContent"></div> | ||
|
||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const user = COR.user; | ||
const repo = COR.repo; | ||
const branch = COR.branch; | ||
//const path = COR.pathContent; | ||
const filterFolders = COR.filterFolders; | ||
const ignoreFiles = COR.ignoreFiles; | ||
// let accessToken = localStorage.getItem( "githubAccessToken" ) || ""; | ||
|
||
// if ( !accessToken || accessToken === "" || accessToken === "null" ) { | ||
|
||
// accessToken = prompt( "Enter GitHub Personal Access Token" ); | ||
|
||
// localStorage.setItem( "githubAccessToken", accessToken ); | ||
|
||
// } | ||
var readmeLink | ||
|
||
async function fetchGitHubRepoContents ( user, repo ) { | ||
const baseUrl = 'https://api.github.com'; | ||
|
||
const headers = new Headers( { | ||
'Accept': 'application/vnd.github+json', | ||
//'Authorization': `token ${ accessToken }` | ||
} ); | ||
|
||
const response = await fetch( `${ baseUrl }/repos/${ user }/${ repo }/git/trees/${ branch }?recursive=1`, { headers } ); | ||
const { tree } = await response.json(); | ||
const div = document.getElementById( 'divContent' ); | ||
|
||
const createTree = ( items, parentPath ) => { | ||
const folderContents = document.createElement( 'div' ); | ||
folderContents.className = 'folder-contents'; | ||
|
||
const trees = items.filter( item => item.type === 'tree' ) | ||
//.filter( item => filterFolders.includes( item ) ); | ||
const blobs = items.filter( item => item.type === 'blob' ); | ||
|
||
//console.log( "trees", trees ); | ||
trees.forEach( item => { | ||
const details = document.createElement( 'details' ); | ||
const summary = document.createElement( 'summary' ); | ||
summary.textContent = item.path.replace( parentPath, '' ); | ||
details.appendChild( summary ); | ||
|
||
const childItems = tree.filter( child => child.path.startsWith( item.path + '/' ) && child.path.split( '/' ).length === item.path.split( '/' ).length + 1 ); | ||
details.appendChild( createTree( childItems, item.path + '/' ) ); | ||
|
||
folderContents.appendChild( details ); | ||
} ); | ||
|
||
blobs.forEach( item => { | ||
const fileLink = document.createElement( 'a' ); | ||
fileLink.textContent = item.path.replace( parentPath, '' ); | ||
fileLink.href = `#${ item.path }`; | ||
//fileLink.target = '_blank'; | ||
|
||
readmeLink = document.createElement( 'a' ); | ||
readmeLink.innerHTML = " <img src='https://pushme-pullyou.github.io/assets/svg/icon-external-link.svg' width=16 >"; | ||
|
||
readmeLink.href = `../../readme.html#${ item.path }`; | ||
const newLine = document.createElement( 'br' ); | ||
|
||
folderContents.appendChild( fileLink ); | ||
folderContents.appendChild( readmeLink ); | ||
folderContents.appendChild( newLine ); | ||
} ); | ||
|
||
return folderContents; | ||
}; | ||
|
||
let topLevelItems = tree.filter( item => { | ||
const pathParts = item.path.split( '/' ); | ||
return pathParts.length === 1; | ||
} ); | ||
|
||
topLevelItems = topLevelItems.filter( item => ( item.type === 'blob' && ignoreFiles.includes( item.path ) === false ) || filterFolders.includes( item.path ) ); | ||
div.appendChild( createTree( topLevelItems, '' ) ); | ||
|
||
//console.log( "topLevelItems", topLevelItems ); | ||
|
||
} | ||
|
||
|
||
fetchGitHubRepoContents( user, repo ); |
Oops, something went wrong.