From 67298f1e5d47fdc0222e0123c9ad766a5f93b6ce Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Tue, 17 Sep 2024 16:04:29 -0700 Subject: [PATCH 1/2] check for presence of config file --- llms_txt/core.py | 4 ++-- nbs/01_core.ipynb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/llms_txt/core.py b/llms_txt/core.py index e8a43bc..7a7b24a 100644 --- a/llms_txt/core.py +++ b/llms_txt/core.py @@ -15,7 +15,7 @@ from fastcore.script import * import httpx from urllib.parse import urlparse -from nbdev.config import get_config +from nbdev.config import * # %% ../nbs/01_core.ipynb def opt_re(s): @@ -74,7 +74,7 @@ def _local_docs_pth(cfg): return cfg.config_path/'_proc'/cfg.doc_path.name def get_doc_content(url): "Fetch content from local file if in nbdev repo." cfg = get_config() - if url.startswith(cfg.doc_host): + if cfg.config_file.exists() and url.startswith(cfg.doc_host): relative_path = urlparse(url).path.lstrip('/') local_path = _local_docs_pth(cfg) / relative_path if local_path.exists(): return local_path.read_text() diff --git a/nbs/01_core.ipynb b/nbs/01_core.ipynb index c65c9fa..c4ab36a 100644 --- a/nbs/01_core.ipynb +++ b/nbs/01_core.ipynb @@ -51,7 +51,7 @@ "from fastcore.script import *\n", "import httpx\n", "from urllib.parse import urlparse\n", - "from nbdev.config import get_config" + "from nbdev.config import *" ] }, { @@ -686,7 +686,7 @@ "def get_doc_content(url):\n", " \"Fetch content from local file if in nbdev repo.\"\n", " cfg = get_config()\n", - " if url.startswith(cfg.doc_host):\n", + " if cfg.config_file.exists() and url.startswith(cfg.doc_host):\n", " relative_path = urlparse(url).path.lstrip('/')\n", " local_path = _local_docs_pth(cfg) / relative_path\n", " if local_path.exists(): return local_path.read_text()\n", @@ -778,8 +778,8 @@ "data": { "text/plain": [ "{'docs': {'internal docs - ed': 34464,\n", - " 'FastHTML quick start': 27376,\n", - " 'HTMX reference': 26427,\n", + " 'FastHTML quick start': 27383,\n", + " 'HTMX reference': 26642,\n", " 'Starlette quick guide': 7936},\n", " 'examples': {'Todo list application': 18558},\n", " 'optional': {'Starlette full documentation': 48331}}" @@ -802,7 +802,7 @@ { "data": { "text/plain": [ - "164321" + "164543" ] }, "execution_count": null, From 27fcf6362f33e448a7108e2f88168b770c001c03 Mon Sep 17 00:00:00 2001 From: Hamel Husain Date: Tue, 17 Sep 2024 16:50:15 -0700 Subject: [PATCH 2/2] check if in nbdev project --- llms_txt/core.py | 2 +- nbs/01_core.ipynb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llms_txt/core.py b/llms_txt/core.py index 7a7b24a..838cb23 100644 --- a/llms_txt/core.py +++ b/llms_txt/core.py @@ -74,7 +74,7 @@ def _local_docs_pth(cfg): return cfg.config_path/'_proc'/cfg.doc_path.name def get_doc_content(url): "Fetch content from local file if in nbdev repo." cfg = get_config() - if cfg.config_file.exists() and url.startswith(cfg.doc_host): + if is_nbdev() and url.startswith(cfg.doc_host): relative_path = urlparse(url).path.lstrip('/') local_path = _local_docs_pth(cfg) / relative_path if local_path.exists(): return local_path.read_text() diff --git a/nbs/01_core.ipynb b/nbs/01_core.ipynb index c4ab36a..331f0de 100644 --- a/nbs/01_core.ipynb +++ b/nbs/01_core.ipynb @@ -686,7 +686,7 @@ "def get_doc_content(url):\n", " \"Fetch content from local file if in nbdev repo.\"\n", " cfg = get_config()\n", - " if cfg.config_file.exists() and url.startswith(cfg.doc_host):\n", + " if is_nbdev() and url.startswith(cfg.doc_host):\n", " relative_path = urlparse(url).path.lstrip('/')\n", " local_path = _local_docs_pth(cfg) / relative_path\n", " if local_path.exists(): return local_path.read_text()\n",