Skip to content

Commit 2eca164

Browse files
committed
New sorting system
1 parent 6f51f2d commit 2eca164

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
*temp*

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Here I'll put any repos that I'm interested in.
2222
<div id="auto-sort-end"/>
2323

2424
## Libs
25+
<div id="auto-sort-start"/>
26+
2527
- `C` <div id="auto-sort-start"/>
2628
- [argparse](https://github.com/cofyc/argparse) - Python's argparse implementation for C
2729
<div id="auto-sort-end"/>
@@ -31,6 +33,7 @@ Here I'll put any repos that I'm interested in.
3133
- `Python` <div id="auto-sort-start"/>
3234
- [DearPyGui](https://github.com/hoffstadt/DearPyGui) - modern, fast and powerful GUI framework for Python based on ImGui
3335
- [tqdm](https://github.com/tqdm/tqdm) - fast, extensible progress bar for Python and CLI
36+
<div id="auto-sort-end"/>
3437
<div id="auto-sort-end"/>
3538

3639
## Homelab

hashes/._README.md.hash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
�@ �� ��RC�Xl��
2-
{T�bi�ؘ�v
1+
Yv��\�W���*���HL�7
2+
�^�� >�Y��

lone_sort_readme.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,46 @@ def sort_readme(file_path: str):
261261
with open(file_path, 'r') as f:
262262
readme = f.readlines()
263263

264-
sorted_readme = []
265-
i = 0
266-
while i < len(readme):
267-
if '<div id="auto-sort-start"/>' in readme[i]:
268-
sorted_readme.append(readme[i])
269-
i += 1
270-
start = i
271-
while i < len(readme) \
272-
and not '<div id="auto-sort-end"/>' in readme[i]:
264+
def sort_block(lines):
265+
sorted_lines = []
266+
i = 0
267+
while i < len(lines):
268+
if '<div id="auto-sort-start"/>' in lines[i]:
269+
sorted_lines.append(lines[i])
273270
i += 1
274-
end = i
275-
# Sort lines ignoring symbols
276-
lines_to_sort = readme[start:end]
277-
sorted_lines = sorted(lines_to_sort, \
278-
key=lambda line: \
279-
re.sub(r'[^a-zA-Z0-9\s]', '', line))
280-
sorted_readme.extend(sorted_lines)
281-
if i < len(readme):
282-
sorted_readme.append(readme[i])
283-
i += 1
271+
start = i
272+
nested_blocks = []
273+
while i < len(lines) and not '<div id="auto-sort-end"/>' in lines[i]:
274+
if '<div id="auto-sort-start"/>' in lines[i]:
275+
nested_start = i
276+
while i < len(lines) and not '<div id="auto-sort-end"/>' in lines[i]:
277+
i += 1
278+
nested_end = i
279+
nested_blocks.append((nested_start, nested_end))
280+
i += 1
281+
end = i
282+
if nested_blocks:
283+
# Sort entire nested blocks
284+
blocks_to_sort = [lines[start:nested_blocks[0][0]]]
285+
for j in range(len(nested_blocks)):
286+
blocks_to_sort.append(lines[nested_blocks[j][0]:nested_blocks[j][1]+1])
287+
if j < len(nested_blocks) - 1:
288+
blocks_to_sort.append(lines[nested_blocks[j][1]+1:nested_blocks[j+1][0]])
289+
blocks_to_sort.append(lines[nested_blocks[-1][1]+1:end])
290+
sorted_blocks = sorted(blocks_to_sort, key=lambda block: re.sub(r'[^a-zA-Z0-9\s+\-*/=%^()]', '', ''.join(block)))
291+
for block in sorted_blocks:
292+
sorted_lines.extend(block)
293+
else:
294+
# Sort lines within the block
295+
lines_to_sort = lines[start:end]
296+
sorted_lines.extend(sorted(lines_to_sort, key=lambda line: re.sub(r'[^a-zA-Z0-9\s+\-*/=%^()]', '', line)))
297+
sorted_lines.append(lines[end])
298+
else:
299+
sorted_lines.append(lines[i])
300+
i += 1
301+
return sorted_lines
302+
303+
sorted_readme = sort_block(readme)
284304

285305
with open(file_path, 'w') as f:
286306
f.writelines(sorted_readme)

0 commit comments

Comments
 (0)