Skip to content

Commit

Permalink
Hardlink the stylesheet instead of creating a copy
Browse files Browse the repository at this point in the history
To tweak the CSS, one would need to navigate to
the data dir, then to the HTML dir of the specific
dictionary, and edit `dict-entry.css`.

That flow is non-obvious. Moreover, it is confusing
because there's a `dict-entry.css` in the workflow
dir, and it could get annoying to see that editing
it isn't reflecting the changes in dictionaries that
have already been imported.

In this change, while importing a new dict, instead
of copying the css file from the workflow dir to
the data dir, we create a hard link instead. That way,
editing the css file in the workflow dir is enough.
Also, it has the added benefit of reflecting the changes
in all the imported dictionaries in one go.
  • Loading branch information
mr-pennyworth committed Feb 20, 2024
1 parent 52381f1 commit 4f7f23b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pyapp/BetterDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def create_html_file(word, definitions, html_dir):
<body> {definition} </body>
</html>'''.encode('utf-8'))


def create_html_files(word_defs_map_items, html_dir):
title = 'Creating HTML files...'
run_parallely_with_progress_bar(
Expand All @@ -119,9 +119,10 @@ def create_html_files(word_defs_map_items, html_dir):
title=title
)

with open(f'{WORKFLOW_DIR}/dict-entry.css', 'rb') as src:
with open(f'{html_dir}/dict-entry.css', 'wb') as dst:
dst.write(src.read())
os.link(
src=f'{WORKFLOW_DIR}/dict-entry.css',
dst=f'{html_dir}/dict-entry.css',
)


class AccumulatedIndexer:
Expand All @@ -143,7 +144,7 @@ def status():
ipb.update(message='')
time.sleep(2)
ipb.finish()



def build_index(word_defs_map_items, dict_id, db_path, html_dir):
Expand Down Expand Up @@ -376,7 +377,7 @@ def create_index(dict_id, db_path):
'quicklookurl',
])
return index


def list_unimported_dicts(import_base_dir):
alfreditems = {'items': []}
Expand Down

0 comments on commit 4f7f23b

Please sign in to comment.