Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pages*: connect several pages through "See also" #12582

Merged

Conversation

vitorhcl
Copy link
Member

@vitorhcl vitorhcl commented Mar 30, 2024

  • The page(s) are in the correct platform directories: common, linux, osx, windows, sunos, android, etc.
  • The page(s) have at most 8 examples.
  • The page description(s) have links to documentation or a homepage.
  • The page(s) follow the content guidelines.
  • The PR title conforms to the recommended templates.

This PR improves the discoverability of similar tools for some categories, such as music players and file managers, for both CLI/TUI and GUI ones. I put the most similar tools first and the least similar, such as GUI->CLI/TUI or CLI/TUI -> GUI, last.

Most importantly, my goal was to connect the pages in such a way that it would be possible to enter any page and discover all the pages in that category.

Some directed graphs that represent the state after the 1st commit of the PR:
multimedia
file-managers
dotfile-managers

The script used for generating the directed graphs
import re
import asyncio
import aiofiles
import aiopath
import argparse
from aioconsole import aprint

async def parse_recommended_pages(content):
  see_also_match = re.search(r'See also: `(.+?)`\.', content)
  if see_also_match:
      recommended_pages = see_also_match.group(1).split('`, `')
      return [page.strip('`') for page in recommended_pages]
  else:
      return []

async def process_page(tldr_root, page):
  platform, page_name = page.split('/')
  page_path = aiopath.Path(tldr_root) / "pages" / platform / f"{page_name}.md"
  async with aiofiles.open(page_path, mode='r') as f:
      content = await f.read()
      recommended_pages = await parse_recommended_pages(content)
      return page_name, recommended_pages

async def process_pages(tldr_root, pages):
  tasks = [process_page(tldr_root, page) for page in pages]
  results = await asyncio.gather(*tasks)
  graph = {page_name: recommended_pages for page_name, recommended_pages in results}
  return graph

async def print_dot_representation(graph):
  await aprint("digraph {")
  for page, recommended_pages in graph.items():
      for recommended_page in recommended_pages:
          if recommended_page in graph and page in graph[recommended_page]:
              if recommended_page < page:
                  await aprint(f'  "{page}" -> "{recommended_page}" [dir="both"]')
          else:
              await aprint(f'  "{page}" -> "{recommended_page}"')
  await aprint("}")

async def main():
  parser = argparse.ArgumentParser(description="Process TLDR pages.")
  parser.add_argument("tldr_root", help="Path to TLDR root directory")
  parser.add_argument("pages", nargs='+', help="List of pages in the format 'platform/page'")
  args = parser.parse_args()
  graph = await process_pages(args.tldr_root, args.pages)
  await print_dot_representation(graph)

if __name__ == "__main__":
  asyncio.run(main())

@vitorhcl vitorhcl requested a review from cyqsimon as a code owner March 30, 2024 18:11
@github-actions github-actions bot added the page edit Changes to an existing page(s). label Mar 30, 2024
@kbdharun kbdharun added the minor change Change(s) to an existing page(s) which is minor. label Apr 3, 2024
@kbdharun kbdharun added the archive Archive of changes made in tldr-pages, etc. label Apr 4, 2024
@kbdharun kbdharun merged commit c0ff7ea into tldr-pages:main Apr 4, 2024
4 checks passed
@vitorhcl vitorhcl deleted the integrate-music-players-see-also branch April 4, 2024 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive Archive of changes made in tldr-pages, etc. minor change Change(s) to an existing page(s) which is minor. page edit Changes to an existing page(s).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants