@@ -24,6 +24,8 @@ class AppConfigs:
2424
2525
2626class Application (apps .AppContainer , cli .Container , apps .PluginMixin ):
27+ _dev_addr : str = "127.0.0.1:8000"
28+
2729 def execute (self ) -> None :
2830 cli .create_group (click .Group ("rats-docs" ), self ).main ()
2931
@@ -62,11 +64,18 @@ def _mkdocs_serve(self) -> None:
6264 category = DeprecationWarning ,
6365 stacklevel = 2 ,
6466 )
65- self .serve ()
67+ self .serve ("127.0.0.1:8000" )
6668
6769 @cli .command ()
68- def serve (self ) -> None :
70+ @click .option (
71+ "--dev-addr" ,
72+ default = "127.0.0.1:8000" ,
73+ help = "address to listen to when running local dev site" ,
74+ show_default = True ,
75+ )
76+ def serve (self , dev_addr : str ) -> None :
6977 """Serve the mkdocs site for the project and monitor files for changes."""
78+ self ._dev_addr = dev_addr
7079 self ._do_mkdocs_things ("serve" )
7180
7281 def _do_mkdocs_things (self , cmd : str ) -> None :
@@ -77,7 +86,8 @@ def _do_mkdocs_things(self, cmd: str) -> None:
7786 mkdocs_config = docs_component .find_path ("mkdocs.yaml" )
7887 mkdocs_staging_path = docs_component .find_path ("dist/docs" )
7988 site_dir_path = docs_component .find_path ("dist/site" )
80- mkdocs_staging_config = docs_component .find_path ("dist/mkdocs.yaml" )
89+ # we append the filename because symlinks get resolved by `find_path()`
90+ mkdocs_staging_config = docs_component .find_path ("dist" ) / "mkdocs.yaml"
8191 # clear any stale state
8292 docs_component .create_or_empty (mkdocs_staging_path )
8393 # start with the contents of our root-docs
@@ -91,14 +101,16 @@ def _do_mkdocs_things(self, cmd: str) -> None:
91101
92102 # replace the mkdocs config with a fresh version
93103 mkdocs_staging_config .unlink (missing_ok = True )
94- docs_component .copy (mkdocs_config , mkdocs_staging_config )
104+ docs_component .symlink (mkdocs_config , mkdocs_staging_config )
95105
96106 args = [
97107 "--config-file" ,
98108 str (mkdocs_staging_config ),
99109 ]
100110 if cmd == "build" :
101111 args .extend (["--site-dir" , str (site_dir_path .resolve ())])
112+ if cmd == "serve" :
113+ args .extend (["--dev-addr" , self ._dev_addr ])
102114
103115 docs_component .run ("mkdocs" , cmd , * args )
104116
0 commit comments