filtering and calling back names with js

Viewed 56

I have all my html files named in the shape of

  • 1_1_first_subpage.html
  • 1_2_second_subpage.html
  • 1_2_1_u_get_the_drill.html

and so on. ive written a script that checks the numbers and classifies them so i have the hierarchy and i have the numbers show up on the webpage in the shape of a subpage path:

  • home | 1 | 2 | 1

as a concept. Now i need to find a way to filter the names in my website folder so that it automatically assigns the number 1 in the first row to index, which i have named 1_index.hmtl (it takes string 1_2_1, filters by that and chooses only file with that in its name, 1_2_1_u_get_the_drill.html) How could i check the names and pull them into js as a string or something?

document.getElementById("demo").innerHTML += "<a href='"+page1+"'>"+page1title+"</a> | <a href='"+page2+"'>"+page2title+"</a>"; my goal is to be able to automate the page1 and page2 variables to link to a html in my folder

full js code:

var url = window.location.pathname;
var filename = url.split("/").pop();
url.substring(url.lastIndexOf('/')+1);
console.log(filename);




//asigna letter prvem znaku v imenu dokumenta
let letter = filename.charAt(0);
console.log(letter);




//preveri če je prvi znak št.
function isNumber(char) {
if (typeof char !== 'string') {
    return false;
}

if (char.trim() === '') { 
 return false;
}

return !isNaN(char);
}



let st1 = letter;
//klikne na element z id 





//če je prvi znak št, preverja naprej, če ni, to javi
if (isNumber(letter)){
console.log("je številka");

     


    
//preveri znak na 3. mestu imena datoteke    
let letter2 = filename.charAt(2);
console.log(letter2);



    //če je tretji znak št, preverja naprej, če ni, to javi
    if (isNumber(letter2))  {
    console.log("drugi znak je številka");
    console.log(st1 +"."+ letter2);   
        
        
        
        
        
            let letter3 = filename.charAt(4); 
            console.log(letter3);
            
        
        
        if (isNumber(letter3))  {
            console.log("je številka");
            console.log(letter +"."+ letter2 + "." + letter3);
            
            
            document.getElementById("demo").innerHTML = letter+ " | 
"+ letter2+ " | "+letter3;
              
            
            
            
            
            document.getElementById("demo").innerHTML += "<a 
href='"+page1+"'>"+page1title+"</a> | <a 
href='"+page2+"'>"+page2title+"</a> | <a 
href='"+page3+"'>"+page3title+"</a>";
                
                
                
                
                
                
                
            }else{
            console.log("tretji znak ni številka");
            console.log("nivo je" +" "+letter +"."+ letter2);
             document.getElementById("demo").innerHTML += "<a 
href='"+page1+"'>"+page1title+"</a> | <a 
 href='"+page2+"'>"+page2title+"</a>";
                
                
                
                
                
                
    }
    }else{
        console.log("drugi znak ni številka");
         document.getElementById("demo").innerHTML += "<a 
href='index.html'>"+letter+"</a>";
       
        
        
        
    }








}else {
console.log("prvi znak ni številka"); 






}  




console.log(isNumber(letter)); // ️ false  
0 Answers
Related