Coverage for /Users/davegaeddert/Developer/dropseed/plain/plain/plain/assets/fingerprints.py: 77%
22 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-23 11:16 -0600
1import json
2from functools import cache
4from plain.runtime import settings
7class AssetsFingerprintsManifest(dict):
8 def __init__(self):
9 self.path = settings.PLAIN_TEMP_PATH / "assets" / "fingerprints.json"
11 def load(self):
12 if self.path.exists():
13 with open(self.path) as f:
14 self.update(json.load(f))
16 def save(self):
17 with open(self.path, "w") as f:
18 json.dump(self, f, indent=2)
21@cache
22def _get_manifest():
23 """
24 A cached function for loading the asset fingerprints manifest,
25 so we don't have to keep loading it from disk over and over.
26 """
27 manifest = AssetsFingerprintsManifest()
28 manifest.load()
29 return manifest
32def get_fingerprinted_url_path(url_path):
33 """
34 Get the final fingerprinted path for an asset URL path.
35 """
36 manifest = _get_manifest()
37 if url_path in manifest:
38 return manifest[url_path]