File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -162,16 +162,19 @@ def update_canonical(fullname, last):
162162 pnew = pathlib .Path (last , * p .parts [1 :])
163163 newcanon = f"{ pre + str (pnew )} "
164164 _log .info (f"{ p } to { pre + str (pnew )} " )
165+ rec = re .compile (b'<link rel="canonical" href=".*"' )
165166 with tempfile .NamedTemporaryFile (delete = False ) as fout :
167+ found = False
166168 with open (fullname , "rb" ) as fin :
167169 for line in fin :
168- if b'<link rel="canonical"' in line :
170+ if not found and b'<link rel="canonical"' in line :
169171 new = bytes (
170172 f'<link rel="canonical" href="{ newcanon } "' , encoding = "utf-8"
171173 )
172- ll = re .sub (b'<link rel="canonical" href=".*"' , new , line )
174+ ll = rec .sub (new , line )
173175 _log .debug (f"new { line } ->{ ll } " )
174176 fout .write (ll )
177+ found = True
175178 else :
176179 fout .write (line )
177180 shutil .move (fout .name , fullname )
You can’t perform that action at this time.
0 commit comments