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):
162
162
pnew = pathlib .Path (last , * p .parts [1 :])
163
163
newcanon = f"{ pre + str (pnew )} "
164
164
_log .info (f"{ p } to { pre + str (pnew )} " )
165
+ rec = re .compile (b'<link rel="canonical" href=".*"' )
165
166
with tempfile .NamedTemporaryFile (delete = False ) as fout :
167
+ found = False
166
168
with open (fullname , "rb" ) as fin :
167
169
for line in fin :
168
- if b'<link rel="canonical"' in line :
170
+ if not found and b'<link rel="canonical"' in line :
169
171
new = bytes (
170
172
f'<link rel="canonical" href="{ newcanon } "' , encoding = "utf-8"
171
173
)
172
- ll = re .sub (b'<link rel="canonical" href="https://github.com/.*"' , new , line )
174
+ ll = rec .sub (new , line )
173
175
_log .debug (f"new { line } ->{ ll } " )
174
176
fout .write (ll )
177
+ found = True
175
178
else :
176
179
fout .write (line )
177
180
shutil .move (fout .name , fullname )
You can’t perform that action at this time.
0 commit comments