This repository has been archived on 2024-04-03. You can view files and clone it, but cannot push or open issues or pull requests.
OLD-GZod01.fr_Source_Code-OLD/main-site/testofsitemap.html

82 lines
2.7 KiB
HTML
Raw Normal View History

2023-03-25 09:29:34 +00:00
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="//api.gzod01.fr/pictures/gzod01.ico">
<link rel="stylesheet" href="//api.gzod01.fr/css/style.css">
<script src="//api.gzod01.fr/scripts/main.js"></script>
<title>sitemap.html</title>
</head>
<body>
<div id="header"></div>
<div class=content>
<h1>Plan Des Sites: </h1>
<ul id="sitemap"></ul>
<script>
function sleep(s) {
let ms = s*1000
return new Promise(resolve => setTimeout(resolve, ms));
}
async function fetchsitemap(){
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
console.log(typeof xhr.responseText);
console.log(xhr.responseText);
}
};
xhr.open('GET', 'http://gzod01.fr/sitemap.json', true);
xhr.setRequestHeader('Accept', 'application/json');
xhr.send(null);
await sleep(2)
const res = JSON.parse(xhr.responseText);
return res
}
function createlinode(url, value, key, strtype, rootofnode){
if(key.startswith(strtype)){
let linknode = document.createelement('li')
linknode.innerhtml='<a href="'+url+value+'">'+key.substring(strtype.length)+'</a>'
rootofnode.appendchild(linknode)
}
}
function preparesitemap(data,rootnode,callurl="",name){
console.log(data, rootnode, callurl, name)
let url = callurl+data['-url-']
rootnode.innerHTML='<a href="'+url+'">'+name+'</a>'
let ulement = document.createElement('ul')
rootnode.appendChild('ul')
Object.entries(data).forEach((quer)=>{
let [rkey, rvalue] = quer
if(rkey.startsWith('dir-')){
let jsonv = JSON.parse(rvalue)
let newrootnode = document.createElement('li')
rootnode.appendChild(newrootnode)
preparesitemap(jsonv,newrootnode, url, rkey.substring('dir-'.length))
}
createlinode(url,rvalue,rkey,"page-",ulement)
createlinode(url,rvalue,rkey,"file-",ulement)
})
}
async function mainsitemap(){
let res = fetchsitemap()
await Object.entries(res).forEach((entry)=>{
console.log('helloworld')
let [rootkey, rootvalue] = entry
if(rootkey.startsWith('site-')){
let valuejsoned = JSON.parse(rootvalue)
let rootofallnode = document.getElementById('sitemap')
let rootofthenode = document.createElement('li')
rootofallnode.appendChild(rootofthenode)
preparesitemap(valuejsoned, rootofthenode, "", rootkey.substring('site-'.length))
}
})}
mainsitemap()
</script>
</div>
<div id="footer"></div>
</body>
</html>