Skip to content

Commit

Permalink
Merge pull request #603 from Lyumih/feature/add-folder-icons-and-sort
Browse files Browse the repository at this point in the history
Добавлена сортировка дирректории и иконки к папкам и файлам
  • Loading branch information
nin-jin committed Jun 21, 2023
2 parents 38ecaf6 + a5df1cb commit 99cc564
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions build/server/server.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ namespace $ {
}

if( dir.type() === 'dir' ) {
const files = new Set<string>( [ '-' ] )
const files = [ {name: '-', type: 'dir'} ]
for( const file of dir.sub() ) {
files.add( file.name() )
if (!files.find(( {name} ) => name === file.name())) {
files.push( {name: file.name(), type: file.type()} )
}
if( /\.meta\.tree$/.test( file.name() ) ) {
const meta = $$.$mol_tree2_from_string( file.text() )
for( const pack of meta.select( 'pack', null ).kids ) {
files.add( pack.type )
if (!files.find(( {name} ) => name !== pack.type))
files.push( {name: pack.type, type: 'dir'} )
}
}
}
Expand All @@ -152,8 +155,18 @@ namespace $ {
a:hover {
background: hsl( 0deg, 0%, 0%, .05 )
}
a[href^="."], a[href^="-"], a[href="node_modules"] {
opacity: 0.5;
}
a[href=".."], a[href="-"] {
opacity: 1;
}
</style>
` + [ ... files ].sort().map( file => `<a href="${file}">${file}</a>` ).join( '\n' )
<a href="..">&#x1F4C1; ..</a>
` + files
.sort($mol_compare_text((item) => item.type))
.map( file => `<a href="${file.name}">${file.type === 'dir' ? '&#x1F4C1;' : '&#128196;'} ${file.name}</a>` )
.join( '\n' )

res.writeHead( 200, {
'Content-Type': 'text/html',
Expand Down

0 comments on commit 99cc564

Please sign in to comment.