Resource preprocessing handles relative links

... but only if they contain "/skin/" as a substring.
This commit is contained in:
Veloman Yunkan 2022-02-27 20:32:57 +04:00
parent 150851b33d
commit c016dfd2ce
3 changed files with 12 additions and 15 deletions

View File

@ -43,15 +43,12 @@ def fill_resource_revisions(resource_file_path):
for resource in read_resource_file(resource_file_path): for resource in read_resource_file(resource_file_path):
resource_revisions[resource] = get_resource_revision(base_dir, resource) resource_revisions[resource] = get_resource_revision(base_dir, resource)
RESOURCE_WITH_CACHEID_URL_PATTERN=r'([^"?]+)\?KIWIXCACHEID([^"]*)' RESOURCE_WITH_CACHEID_URL_PATTERN=r'((.*)/skin/([^"?]+))\?KIWIXCACHEID([^"]*)'
def set_cacheid(resource_matchobj): def set_cacheid(resource_matchobj):
path = resource_matchobj.group(1) path = resource_matchobj.group(1)
resource = path resource = 'skin/' + resource_matchobj.group(3)
root_prefix = '{{root}}/' extra_query = resource_matchobj.group(4)
if resource.startswith(root_prefix):
resource = resource[len(root_prefix):]
extra_query = resource_matchobj.group(2)
cacheid = 'cacheid=' + resource_revisions[resource] cacheid = 'cacheid=' + resource_revisions[resource]
return f'{path}?{cacheid}{extra_query}' return f'{path}?{cacheid}{extra_query}'

View File

@ -171,25 +171,25 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-regular-download"> <div class="modal-regular-download">
<a href="${downloadLink}" download> <a href="${downloadLink}" download>
<img src="../skin/download.png" alt="direct download" /> <img src="../skin/download.png?KIWIXCACHEID" alt="direct download" />
<div>Direct</div> <div>Direct</div>
</a> </a>
</div> </div>
<div class="modal-regular-download"> <div class="modal-regular-download">
<a href="${downloadLink}.sha256" download> <a href="${downloadLink}.sha256" download>
<img src="../skin/hash.png" alt="download hash" /> <img src="../skin/hash.png?KIWIXCACHEID" alt="download hash" />
<div>Sha256 hash</div> <div>Sha256 hash</div>
</a> </a>
</div> </div>
<div class="modal-regular-download"> <div class="modal-regular-download">
<a href="${downloadLink}.magnet" target="_blank"> <a href="${downloadLink}.magnet" target="_blank">
<img src="../skin/magnet.png" alt="download magnet" /> <img src="../skin/magnet.png?KIWIXCACHEID" alt="download magnet" />
<div>Magnet link</div> <div>Magnet link</div>
</a> </a>
</div> </div>
<div class="modal-regular-download"> <div class="modal-regular-download">
<a href="${downloadLink}.torrent" download> <a href="${downloadLink}.torrent" download>
<img src="../skin/bittorrent.png" alt="download torrent" /> <img src="../skin/bittorrent.png?KIWIXCACHEID" alt="download torrent" />
<div>Torrent file</div> <div>Torrent file</div>
</a> </a>
</div> </div>

View File

@ -319,15 +319,15 @@ R"EXPECTEDRESULT( src="/ROOT/skin/jquery-ui/external/jquery/jquery.js?cache
src: url("/ROOT/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype"); src: url("/ROOT/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype");
<script src="/ROOT/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script> <script src="/ROOT/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
<script src="/ROOT/skin/iso6391To3.js?cacheid=ecde2bb3"></script> <script src="/ROOT/skin/iso6391To3.js?cacheid=ecde2bb3"></script>
<script type="text/javascript" src="/ROOT/skin/index.js?cacheid=ea9ce83c" defer></script> <script type="text/javascript" src="/ROOT/skin/index.js?cacheid=f2c89cb2" defer></script>
)EXPECTEDRESULT" )EXPECTEDRESULT"
}, },
{ {
/* url */ "/ROOT/skin/index.js", /* url */ "/ROOT/skin/index.js",
R"EXPECTEDRESULT( <img src="../skin/download.png" alt="direct download" /> R"EXPECTEDRESULT( <img src="../skin/download.png?cacheid=a39aa502" alt="direct download" />
<img src="../skin/hash.png" alt="download hash" /> <img src="../skin/hash.png?cacheid=f836e872" alt="download hash" />
<img src="../skin/magnet.png" alt="download magnet" /> <img src="../skin/magnet.png?cacheid=73b6bddf" alt="download magnet" />
<img src="../skin/bittorrent.png" alt="download torrent" /> <img src="../skin/bittorrent.png?cacheid=4f5c6882" alt="download torrent" />
)EXPECTEDRESULT" )EXPECTEDRESULT"
}, },
{ {