Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions scripts/auto_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,7 @@
with open('src/data/apps.json', 'r') as f:
apps = json.load(f)

# Build a mapping of app names to their programmatic hub links
app_links = {}
for app in apps:
app_links[app['name'].lower()] = {
'name': app['name'],
'link': f"/apps/{app['id']}/"
}

blog_files = glob.glob('src/content/blog/*.md')
standalone_files = glob.glob('src/pages/*.astro')

files_to_check = blog_files + [f for f in standalone_files if os.path.basename(f) not in ['index.astro', '404.astro', 'sitemap.astro', 'sitemap-page.astro']]

for file_path in files_to_check:
with open(file_path, 'r') as f:
content = f.read()

def find_matches(content, app_links):
content_lower = content.lower()
matches = []

Expand All @@ -33,9 +17,9 @@
if app_data['link'] not in content:
matches.append(app_data)

if not matches:
continue
return matches

def inject_links(file_path, content, matches):
# Inject links safely at the bottom of the file
if file_path.endswith('.md'):
# Just append to MD
Expand Down Expand Up @@ -65,3 +49,27 @@
with open(file_path, 'w') as f:
f.write(content)
print(f"Injected links into {file_path}")

# Build a mapping of app names to their programmatic hub links
app_links = {}
for app in apps:
app_links[app['name'].lower()] = {
'name': app['name'],
'link': f"/apps/{app['id']}/"
}

blog_files = glob.glob('src/content/blog/*.md')
standalone_files = glob.glob('src/pages/*.astro')

files_to_check = blog_files + [f for f in standalone_files if os.path.basename(f) not in ['index.astro', '404.astro', 'sitemap.astro', 'sitemap-page.astro']]

for file_path in files_to_check:
with open(file_path, 'r') as f:
content = f.read()

matches = find_matches(content, app_links)

if not matches:
continue

inject_links(file_path, content, matches)