mkdocs-obsidian-interactive-graph-plugin 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 daxcore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.1
2
+ Name: mkdocs-obsidian-interactive-graph-plugin
3
+ Version: 0.1.0
4
+ Summary: A MkDocs plugin that generates a obsidian like interactive graph
5
+ Home-page: https://github.com/daxcore/mkdocs-obsidian-interactive-graph
6
+ Author: daxcore
7
+ Author-email: 300ccda6-8d43-4f23-808e-961e653ff7d6@anonaddy.com
8
+ License: MIT
9
+ Keywords: mkdocs
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Information Technology
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3.6
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Requires-Python: >=3.6
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: mkdocs-material>=9.0.0
25
+
26
+ # Interactive Graph for Material for MkDocs
27
+ Plugin for Material for MkDocs to draw an interactive graph like Obsidian.
28
+ Just available for non-mobile website yet.
29
+
30
+ # Installation
31
+ `pip install mkdocs-obsidian-interactive-graph-plugin`
32
+
33
+ # Usage
34
+ Activate the plugin in mkdocs.yml, but note that this plugin has to be located before plugins, that replace wikilinks to markdown links. Currently just wikilinks like `[[Link]]` are supported.
35
+ ```
36
+ plugins:
37
+ - obsidian-interactive-graph
38
+ ```
39
+
40
+ # Development
41
+ Adapt the `.env` and `mkdocs.yml` files to your needs.
42
+ Build and start the Docker via `docker compose up --build`.
43
+
44
+ # References
45
+ * https://www.mkdocs.org/
46
+ * https://squidfunk.github.io/mkdocs-material/
47
+ * https://github.com/ndy2/mkdocs-obsidian-support-plugin/tree/main
48
+ * https://github.com/GooRoo/mkdocs-obsidian-bridge
49
+ * https://github.com/blueswen/mkdocs-glightbox
50
+ * https://echarts.apache.org
@@ -0,0 +1,25 @@
1
+ # Interactive Graph for Material for MkDocs
2
+ Plugin for Material for MkDocs to draw an interactive graph like Obsidian.
3
+ Just available for non-mobile website yet.
4
+
5
+ # Installation
6
+ `pip install mkdocs-obsidian-interactive-graph-plugin`
7
+
8
+ # Usage
9
+ Activate the plugin in mkdocs.yml, but note that this plugin has to be located before plugins, that replace wikilinks to markdown links. Currently just wikilinks like `[[Link]]` are supported.
10
+ ```
11
+ plugins:
12
+ - obsidian-interactive-graph
13
+ ```
14
+
15
+ # Development
16
+ Adapt the `.env` and `mkdocs.yml` files to your needs.
17
+ Build and start the Docker via `docker compose up --build`.
18
+
19
+ # References
20
+ * https://www.mkdocs.org/
21
+ * https://squidfunk.github.io/mkdocs-material/
22
+ * https://github.com/ndy2/mkdocs-obsidian-support-plugin/tree/main
23
+ * https://github.com/GooRoo/mkdocs-obsidian-bridge
24
+ * https://github.com/blueswen/mkdocs-glightbox
25
+ * https://echarts.apache.org
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.1
2
+ Name: mkdocs-obsidian-interactive-graph-plugin
3
+ Version: 0.1.0
4
+ Summary: A MkDocs plugin that generates a obsidian like interactive graph
5
+ Home-page: https://github.com/daxcore/mkdocs-obsidian-interactive-graph
6
+ Author: daxcore
7
+ Author-email: 300ccda6-8d43-4f23-808e-961e653ff7d6@anonaddy.com
8
+ License: MIT
9
+ Keywords: mkdocs
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Information Technology
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3.6
15
+ Classifier: Programming Language :: Python :: 3.7
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Requires-Python: >=3.6
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: mkdocs-material>=9.0.0
25
+
26
+ # Interactive Graph for Material for MkDocs
27
+ Plugin for Material for MkDocs to draw an interactive graph like Obsidian.
28
+ Just available for non-mobile website yet.
29
+
30
+ # Installation
31
+ `pip install mkdocs-obsidian-interactive-graph-plugin`
32
+
33
+ # Usage
34
+ Activate the plugin in mkdocs.yml, but note that this plugin has to be located before plugins, that replace wikilinks to markdown links. Currently just wikilinks like `[[Link]]` are supported.
35
+ ```
36
+ plugins:
37
+ - obsidian-interactive-graph
38
+ ```
39
+
40
+ # Development
41
+ Adapt the `.env` and `mkdocs.yml` files to your needs.
42
+ Build and start the Docker via `docker compose up --build`.
43
+
44
+ # References
45
+ * https://www.mkdocs.org/
46
+ * https://squidfunk.github.io/mkdocs-material/
47
+ * https://github.com/ndy2/mkdocs-obsidian-support-plugin/tree/main
48
+ * https://github.com/GooRoo/mkdocs-obsidian-bridge
49
+ * https://github.com/blueswen/mkdocs-glightbox
50
+ * https://echarts.apache.org
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ mkdocs_obsidian_interactive_graph_plugin.egg-info/PKG-INFO
5
+ mkdocs_obsidian_interactive_graph_plugin.egg-info/SOURCES.txt
6
+ mkdocs_obsidian_interactive_graph_plugin.egg-info/dependency_links.txt
7
+ mkdocs_obsidian_interactive_graph_plugin.egg-info/entry_points.txt
8
+ mkdocs_obsidian_interactive_graph_plugin.egg-info/requires.txt
9
+ mkdocs_obsidian_interactive_graph_plugin.egg-info/top_level.txt
10
+ obsidian_interactive_graph/__init__.py
11
+ obsidian_interactive_graph/plugin.py
@@ -0,0 +1,2 @@
1
+ [mkdocs.plugins]
2
+ obsidian-interactive-graph = obsidian_interactive_graph.plugin:ObsidianInteractiveGraphPlugin
@@ -0,0 +1,121 @@
1
+ import json
2
+ import os
3
+ import re
4
+
5
+ from mkdocs.config.defaults import MkDocsConfig
6
+ from mkdocs.plugins import BasePlugin, get_plugin_logger
7
+ from mkdocs.structure.files import Files as MkDocsFiles
8
+ from mkdocs.structure.pages import Page as MkDocsPage
9
+ from mkdocs.structure.nav import Navigation as MkDocsNav
10
+
11
+
12
+ class ObsidianInteractiveGraphPlugin(BasePlugin):
13
+ def __init__(self):
14
+ super().__init__()
15
+ self.logger = get_plugin_logger(__name__)
16
+ self.nodes = {}
17
+ self.site_path = ""
18
+ self.current_id = 0
19
+ self.data = json.loads('{ "nodes": [], "links": [] }')
20
+
21
+ @property
22
+ def id(self):
23
+ current_id = self.current_id
24
+ self.current_id += 1
25
+ return current_id
26
+
27
+ def get_path(self, base: str, *argv: list[str]) -> str:
28
+ from urllib.parse import urljoin
29
+ result = base
30
+ for path in argv:
31
+ result = urljoin(result, path)
32
+ return result
33
+
34
+ def get_page_path(self, page: MkDocsPage) -> str:
35
+ return self.get_path(self.site_path, page.file.src_uri).strip(".md")
36
+
37
+ def page_if_exists(self, page: str) -> str:
38
+ page = self.get_path(self.site_path, page)
39
+ for k,_ in self.nodes.items():
40
+ if k == page:
41
+ return page
42
+ return None
43
+
44
+ def collect_pages(self, nav: MkDocsNav, config: MkDocsConfig):
45
+ for page in nav.pages:
46
+ page.read_source(config=config)
47
+ self.nodes[self.get_page_path(page)] = {
48
+ "id": self.id,
49
+ "title": page.title,
50
+ "url": page.abs_url,
51
+ "symbolSize": 0,
52
+ "markdown": page.markdown,
53
+ "is_index": page.is_index
54
+ }
55
+
56
+ def parse_markdown(self, markdown: str, page: MkDocsPage):
57
+ # wikilinks: [[Link#Anchor|Custom Text]], just the link is needed
58
+ WIKI_PATTERN = re.compile(r"(?<!\!)\[\[(?P<wikilink>[^\|^\]^\#]{1,})(?:.*)\]\]")
59
+ for match in re.finditer(WIKI_PATTERN, markdown):
60
+ wikilink = match.group('wikilink')
61
+ self.logger.warning(wikilink)
62
+
63
+ # get the nodes key
64
+ page_path = self.get_page_path(page)
65
+
66
+ # search page path of target page
67
+ target_page_path = ""
68
+
69
+ # link to self if wikilink is index and current page is index
70
+ if wikilink == "index" and self.nodes[page_path]["is_index"]:
71
+ target_page_path = page_path
72
+ else:
73
+ # 1st: link to global page if exists
74
+ # 2nd: search relative
75
+ wikilink = self.page_if_exists(wikilink) or self.page_if_exists(self.get_path(page_path, wikilink)) or wikilink
76
+
77
+ # find something that matches: shortest path depth
78
+ abslen = None
79
+ for k,_ in self.nodes.items():
80
+ for _ in re.finditer(re.compile(r"(.*" + wikilink + r")"), k):
81
+ curlen = k.count('/')
82
+ if abslen == None or curlen < abslen:
83
+ target_page_path = k
84
+ abslen = curlen
85
+
86
+ link = {
87
+ "source": str(self.nodes[page_path]["id"]),
88
+ "target": str(self.nodes[target_page_path]["id"])
89
+ }
90
+ self.data["links"].append(link)
91
+
92
+ # rate +1 if page has link of is linked
93
+ self.nodes[page_path]["symbolSize"] = self.nodes[page_path].get("symbolSize", 1) + 1
94
+ self.nodes[target_page_path]["symbolSize"] = self.nodes[target_page_path].get("symbolSize", 1) + 1
95
+
96
+ def create_graph_json(self, config: MkDocsConfig):
97
+ for i, (k,v) in enumerate(self.nodes.items()):
98
+ node = {
99
+ "id": str(i),
100
+ "name": v["title"],
101
+ "symbolSize": v["symbolSize"],
102
+ "value": v["url"]
103
+ }
104
+ self.data["nodes"].append(node)
105
+
106
+ filename = os.path.join(config['site_dir'], 'assets', 'javascripts', 'graph.json')
107
+ os.makedirs(os.path.dirname(filename), exist_ok=True)
108
+ with open(filename, 'w') as file:
109
+ json.dump(self.data, file, sort_keys=False, indent=2)
110
+
111
+ def on_config(self, config: MkDocsConfig, **kwargs):
112
+ self.site_path = config.site_name + "/"
113
+
114
+ def on_nav(self, nav: MkDocsNav, files: MkDocsFiles, config: MkDocsConfig, **kwargs):
115
+ self.collect_pages(nav, config)
116
+
117
+ def on_page_markdown(self, markdown: str, page: MkDocsPage, config: MkDocsConfig, files: MkDocsFiles, **kwargs):
118
+ self.parse_markdown(markdown, page)
119
+
120
+ def on_env(self, env, config: MkDocsConfig, files: MkDocsFiles):
121
+ self.create_graph_json(config)
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,44 @@
1
+ import os
2
+
3
+ from setuptools import setup, find_packages
4
+
5
+ VERSION_NUMBER = '0.1.0'
6
+
7
+ def read_file(fname):
8
+ return open(os.path.join(os.path.dirname(__file__), fname)).read()
9
+
10
+ setup(
11
+ name='mkdocs-obsidian-interactive-graph-plugin',
12
+ version=VERSION_NUMBER,
13
+ description='A MkDocs plugin that generates a obsidian like interactive graph',
14
+ long_description=read_file('README.md'),
15
+ long_description_content_type='text/markdown',
16
+ keywords='mkdocs',
17
+ url='https://github.com/daxcore/mkdocs-obsidian-interactive-graph',
18
+ author='daxcore',
19
+ author_email='300ccda6-8d43-4f23-808e-961e653ff7d6@anonaddy.com',
20
+ license='MIT',
21
+ python_requires='>=3.6',
22
+ install_requires=[
23
+ 'mkdocs-material>=9.0.0'
24
+ ],
25
+ classifiers=[
26
+ 'Development Status :: 4 - Beta',
27
+ 'Intended Audience :: Developers',
28
+ 'Intended Audience :: Information Technology',
29
+ 'License :: OSI Approved :: MIT License',
30
+ 'Programming Language :: Python :: 3.6',
31
+ 'Programming Language :: Python :: 3.7',
32
+ 'Programming Language :: Python :: 3.8',
33
+ 'Programming Language :: Python :: 3.9',
34
+ 'Programming Language :: Python :: 3.10',
35
+ 'Programming Language :: Python :: 3.11',
36
+ 'Programming Language :: Python :: 3.12'
37
+ ],
38
+ packages=find_packages(),
39
+ entry_points={
40
+ 'mkdocs.plugins': [
41
+ 'obsidian-interactive-graph = obsidian_interactive_graph.plugin:ObsidianInteractiveGraphPlugin'
42
+ ]
43
+ }
44
+ )