Skip to content
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

How to customize res path when writing Appledict #412

Closed
EvanLuo42 opened this issue Jan 18, 2023 · 6 comments
Closed

How to customize res path when writing Appledict #412

EvanLuo42 opened this issue Jan 18, 2023 · 6 comments

Comments

@EvanLuo42
Copy link

If I just use image with <img src="img/some.jpeg">, some.jpeg will not be moved to OtherResources when generating Appledict source. I checked write options, but I did not find an option which is satisfied with this need.

@EvanLuo42 EvanLuo42 changed the title How to custom res path when writing Appledict How to customize res path when writing Appledict Jan 18, 2023
@ilius
Copy link
Owner

ilius commented Jan 18, 2023

Can you upload the source glossary you are coverting from?

@EvanLuo42
Copy link
Author

Can you upload the source glossary you are coverting from?

Actually I’m not converting. I’m using pyglossary to write entries into a new dict.

@EvanLuo42
Copy link
Author

EvanLuo42 commented Jan 19, 2023

And here is the code:

Glossary.init()

glossary = Glossary()
file_loader = FileSystemLoader('templates')
env = Environment(loader=file_loader)
template = env.get_template('template.html')
with open('dict.json') as f:
    dictionary: list = json.load(f)

for item in dictionary.__iter__():
    glossary.addEntryObj(glossary.newEntry(
        item['symbol'],
        template.render(
            alias_name=item['symbol'],
            fullname=item['name'],
            details=item['details'],
        ),
        defiFormat='h',
    ))
    glossary.addEntryObj(glossary.newEntry(
        item['name'],
        template.render(
            alias_name=item['symbol'],
            fullname=item['name'],
            details=item['details'],
        ),
        defiFormat='h',
    ))

glossary.setInfo("title", "Elements Dictionary")
glossary.setInfo("author", "EvanLuo42")
glossary.write(filename='Elements Dictionary', format='AppleDict', css='templates/template.css')
<div class="words">
    <div class="word"><h1 id="alias-name">{{ alias_name }}</h1></div>
    &nbsp;
    <div class="word"><h3 id="full-name">{{ fullname }}</h3></div>
</div>
<div class="defi">
    {% for amount_name, amount in details.items() %}
    <div class="content">
        <b class="amount">{{ amount }}</b>
        <div class="amount_name">{{ amount_name }}</div>
        <img src="img/a.jpeg">
    </div>
    {% endfor %}
</div>

P.S. That <img> is just for demonstration. I haven't used it yet.

@EvanLuo42
Copy link
Author

EvanLuo42 commented Jan 19, 2023

What I want to do is to add some pictures into some entries. But if I just write <img src="my picture directory">, this picture directory will not be added to OtherResources when generating AppleDict. I'm wondering if there is a way that can let me set a resource directory like specifying a css file.

@ilius
Copy link
Owner

ilius commented Jan 19, 2023

Then you need to add your images (or css, js or other files) as Data Entries.

For example:

with open("img/a.jpeg") as fp:
	glos.addEntryObj(glos.newDataEntry("img/a.jpeg", fp.read()))

The first argument to newDataEntry must be the relative path that your html points at.

@EvanLuo42
Copy link
Author

Then you need to add your images (or css, js or other files) as Data Entries.

For example:

with open("img/a.jpeg") as fp:
	glos.addEntryObj(glos.newDataEntry("img/a.jpeg", fp.read()))

The first argument to newDataEntry must be the relative path that your html points at.

Ok, got it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants