File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -845,11 +845,34 @@ def render_md_sources_to_html(self):
845845 sitemap = "\n " .join (all_urls_list ) + "\n "
846846 autogen_utils .save_file (Path (self .site_dir ) / "sitemap.txt" , sitemap )
847847
848+ # Examples landing page
849+ self .generate_examples_landing_page ()
850+
848851 # Redirects
852+ self .check_redirects ()
849853 shutil .copytree (self .redirects_dir , self .site_dir , dirs_exist_ok = True )
850854
851- # Examples landing page
852- self .generate_examples_landing_page ()
855+ def check_redirects (self ):
856+ """Validate our redirects"""
857+ for file in Path (self .redirects_dir ).glob ("**/*.html" ):
858+ with open (file ) as f :
859+ content = f .read ()
860+ # Read url.
861+ url = content [content .find ("URL=" ) + 5 :]
862+ url = url [: url .find ("'" )]
863+ # Strip to path.
864+ path = url .replace ("https://keras.io/" , "" )
865+ target = Path (self .site_dir ) / Path (path )
866+ if not target .exists ():
867+ raise ValueError (
868+ f"Redirect target { path } does not exist referenced "
869+ f"from file { file } ."
870+ )
871+ site_path = Path (self .site_dir ) / file .relative_to (self .redirects_dir )
872+ if site_path .exists ():
873+ raise ValueError (
874+ f"Redirect at { file } would overwrite a real page."
875+ )
853876
854877 def render_single_file (self , src_location , fname , nav ):
855878 if not fname .endswith (".md" ):
You can’t perform that action at this time.
0 commit comments