You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.6 KiB
61 lines
2.6 KiB
// https://cdnjs.com/libraries/sql.js
|
|
// https://github.com/sql-js/sql.js?tab=readme-ov-file#loading-a-database-from-a-server
|
|
|
|
function filterTemplateExample( contentFilename ){
|
|
let file = filesWithMetadata[contentFilename]
|
|
if (!file) return
|
|
// can be removed for URLs as those are not with metadata
|
|
|
|
let contentType = file.contentType
|
|
|
|
// mereology option
|
|
let openingOptions = filesWithMetadata[contentFilename].openingOptions
|
|
// can be used via e.g. showFile("https://fabien.benetou.fr/?action=source",{ mereology:"whole"})
|
|
|
|
// filtering, only applying what's next to a certain content type and/or with filename filtering with .startsWith() .endsWith() .includes() or regex
|
|
if ( contentType.includes("xml") && contentFilename.includes("pdfxml/") ) {
|
|
console.log('it is a pdf unpacked file', contentFilename)
|
|
|
|
/*
|
|
// example of zip support
|
|
fetch( contentFilename ).then( r => r.blob(r) ).then( file => zip.loadAsync(file) ).then( f => {
|
|
console.log(f.files)
|
|
let filenameFromZip = Object.entries( f.files ).filter( i => i[0].includes("partialfilename.ext") ).map( i => i[0] )[0]
|
|
f.files[filenameFromZip].async("string").then( dyn_content => {
|
|
json = JSON.parse( dyn_content )
|
|
})
|
|
})
|
|
*/
|
|
|
|
fetch( contentFilename ).then( r => r.text() ).then( txt => {
|
|
|
|
console.log( "mereology", openingOptions.mereology )
|
|
switch( openingOptions.mereology ) {
|
|
case "whole":
|
|
addNewNote(txt, "0 1.4 -.8")
|
|
break;
|
|
case "listonly":
|
|
default:
|
|
txt.replaceAll('* ','').split('\n').map( (c,i) => addNewNote(c, "0 "+(1+i/10)+" -.8") )
|
|
}
|
|
|
|
const rootEl = document.createElement("a-entity")
|
|
// having a root element to attach on makes manipulation later on easier and safer, bringing a context for later modifications
|
|
file.filteredEl = rootEl
|
|
rootEl.test = _ => console.log( 'test' )
|
|
// function that can then be called on the created element later on
|
|
// e.g. filesWithMetadata["https://companion.benetou.fr/saved/pdfxml/3209542.3209570.xml"].filteredEl.nextPage('ok')
|
|
AFRAME.scenes[0].appendChild(rootEl)
|
|
|
|
AFRAME.scenes[0].emit('templateexampleloaded', contentFilename)
|
|
// to use the event consider :
|
|
//AFRAME.scenes[0].addEventListener("templateexampleloaded", e => console.log(e))
|
|
|
|
} );
|
|
}
|
|
applyNextFilter( contentFilename )
|
|
// can stop here or move on to the next filter that might or not be applied
|
|
}
|
|
sequentialFilters.push( filterTemplateExample )
|
|
// adding this to the list of filters to go through, order matters
|
|
// typically one would be generic filters first then more specific ones after
|
|
|