-
Notifications
You must be signed in to change notification settings - Fork 21
Python script to generate a .json.gz file per each locale #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abaevbog
wants to merge
11
commits into
zotero:master
Choose a base branch
from
abaevbog:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c7e4f2d
python script to generate a .json.gz file per each locale
def1906
typo fix
d15f816
generating .htaccess file + cleanup
962f3c3
slightly refined htaccess rules
31e232e
htaccess rules with locale as query parameter instead of path
b90db18
defaulting to schema.json if gzip is not accepted, rules to serve cor…
abaevbog 498b190
skipping rules if url does not start with /schema
abaevbog 4ccd056
updated filter to not skip rules on zotero-schema
abaevbog e3e1ed5
simplifications for the rules
abaevbog 7aef704
No L in skip rule
abaevbog 393ffe5
typo fix and last L
abaevbog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ if os.path.exists(locales_folder): | |
| os.mkdir(locales_folder) | ||
|
|
||
| # Begin by checking if gzip is supported. If not - return schema.json | ||
| htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/(schema|zotero-schema) | ||
| RewriteRule ".?" "-" [S=LINES_TO_SKIP] | ||
| htaccess_rules = f'''RewriteCond %{{REQUEST_URI}} !^/schema | ||
| RewriteRule ".?" "-" [S=LINES_TO_SKIP,L] | ||
| RewriteCond %{{HTTP:Accept-Encoding}} !gzip | ||
| RewriteRule ^schema(/.*)?$ /zotero-schema/schema.json [QSD,L] | ||
| RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({'|'.join(schema['locales'].keys())})(?:&|$) | ||
|
|
@@ -65,21 +65,21 @@ for country_code in htaccess_mapings.keys(): | |
| htaccess_mapings[country_code].sort(key=locale_sort_key) | ||
| # Each rule is only applid is gzip encoding is accepted | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| htaccess_rules += f'''RewriteCond %{{QUERY_STRING}} (?:^|&)locale=({country_code}(-.*)?)(?:&|$) | ||
| RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.json.gz [QSD] | ||
| RewriteRule ^schema(/.*)?$ /zotero-schema/locales/{htaccess_mapings[country_code][0]}.json.gz [QSD,L] | ||
| ''' | ||
|
|
||
| # Catch all for default schema with all locales | ||
| htaccess_rules += '''RewriteRule ^schema$ /zotero-schema/schema.json.gz [QSD]''' | ||
| htaccess_rules += '''RewriteRule ^schema$ /zotero-schema/schema.json.gz [QSD,L]''' | ||
|
|
||
| #Rules to serve correct content type and prevent double gzip matching all locales | ||
| htaccess_rules += ''' | ||
| RewriteRule ^zotero-schema/schema\.json.gz$ - [T=application/json,E=no-gzip:1] | ||
| RewriteRule ^zotero-schema/locales/.*\.json.gz$ - [T=application/json,E=no-gzip:1]''' | ||
|
|
||
| htaccess_rules += f''' | ||
| <FilesMatch \"(schema|{'|'.join(schema['locales'].keys())})\.json\.gz$\"> | ||
| # Serve correct encoding type | ||
| Header append Content-Encoding gzip | ||
| # Set correct content type | ||
| Header set Content-Type application/json | ||
| # Prevent double-gzip | ||
| SetEnv no-gzip 1 | ||
| # Force proxies to cache gzipped & non-gzipped schema file separately | ||
| Header append Vary Accept-Encoding | ||
| # CORS | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lisn't right here, though — that breaks the dataserver completely by skipping the main redirect at the bottom of the file.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean - I removed it.
For some reason when I was testing it on my local dataserver setup, all non /schema requests reached index.php as they were supposed to even with that L flag. Probably can blame it on my local dataserver or apache setup