From 884526e7e127a92a2e76563ce6f2c5310c21d590 Mon Sep 17 00:00:00 2001 From: JK Date: Mon, 21 Jul 2025 10:31:10 +0900 Subject: [PATCH] =?UTF-8?q?generate=5Ftoc.py=20-=20=ED=83=90=EC=83=89?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20breadcrumbs=20=EC=B6=94=EC=B6=9C=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Breadcrumbs 를 [Title](/uri/path) 형식으로 추출합니다. - 첫번째 항목이 'QueryPie Docs for v10' 인 경우, 이 항목을 삭제합니다. - `./` 로 시작하는 상대경로로 /uri/path 를 생성합니다. - ZWSP 를 제목에서 제거합니다. --- docs/generate_toc.py | 54 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/docs/generate_toc.py b/docs/generate_toc.py index 0c95e8e27..cbf2dbe6c 100755 --- a/docs/generate_toc.py +++ b/docs/generate_toc.py @@ -7,6 +7,8 @@ import os from collections import defaultdict +ZWSP = '\u200b' + # Parse sitemap.xml and extract all URLs def parse_sitemap(filename): tree = ET.parse(filename) @@ -15,6 +17,43 @@ def parse_sitemap(filename): urls = [url.find('ns:loc', ns).text.strip() for url in root.findall('ns:url', ns)] return urls +# Extract and format breadcrumbs from soup object and current url +# Returns a formatted breadcrumb string +def extract_breadcrumbs(soup, current_url): + """ + Extract and format breadcrumbs from soup object and current url. + Returns a formatted breadcrumb string. + - Each breadcrumb is formatted as [Title](/uri/path) + - The first breadcrumb 'QueryPie Docs for v10' is removed if present + - The path '/querypie-manual/11.0.0/' is replaced with './' + - Any '../../../ko' or similar parent references are removed + - All paths are made relative to './' + - ZWSP (U+200B) is removed from titles + - Newline characters in breadcrumb items are replaced with space + """ + breadcrumbs = [] + ol = soup.find('ol', class_='breadcrumbs') + if ol: + for li in ol.find_all('li'): + a = li.find('a') + if a: + text = a.get_text(separator=' ', strip=True).replace('\n', ' ').replace('\r', ' ') + href = a.get('href', '') + # Remove parent directory references and 'ko' from href + # Also remove any ../../../ko or similar + parts = [part for part in href.split('/') if part not in ('..', '.', '', 'ko', 'en', 'ja')] + href_clean = '/' + '/'.join(parts) if parts else '/' + # Replace /querypie-manual/11.0.0/ with ./ + href_clean = href_clean.replace('/querypie-manual/11.0.0/', './') + breadcrumbs.append(f'[{text}]({href_clean})') + # Remove first breadcrumb if it is 'QueryPie Docs for v10' + if breadcrumbs and breadcrumbs[0].startswith('[QueryPie Docs for v10]'): + breadcrumbs = breadcrumbs[1:] + # Replace any newline in breadcrumb items with space and remove ZWSP + breadcrumbs = [b.replace('\n', ' ').replace('\r', ' ').replace(ZWSP, '') for b in breadcrumbs] + breadcrumb_str = '/'.join(breadcrumbs) + return breadcrumb_str + # Visit the URL and extract the document title and breadcrumbs # Returns (title, breadcrumb_str, error_message) def fetch_title_and_breadcrumbs(url): @@ -30,17 +69,10 @@ def fetch_title_and_breadcrumbs(url): title = '' # Remove any newline characters from title title = title.replace('\n', ' ').replace('\r', ' ') - # Extract breadcrumbs from