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

Asset Documentation. #72

Open
Chaitanyabsprip opened this issue Feb 22, 2023 · 2 comments
Open

Asset Documentation. #72

Chaitanyabsprip opened this issue Feb 22, 2023 · 2 comments

Comments

@Chaitanyabsprip
Copy link

Is your feature request related to a problem? Please describe.
It's difficult to figure out whether some asset already exists. It would be great to have a markdown file with preview for all image assets.

Describe the solution you'd like
I am already using spider to generate the constants file. It would be nice if this functionality could be added to spider itself.

Describe alternatives you've considered
I created a small python script that generates a markdown file with preview for all image assets.

@BirjuVachhani
Copy link
Owner

@Chaitanyabsprip I don't know if this should be a part of the package. Yes it would be convenient to see a markdown file. Or you can just open finder/explorer and see what images are there. IDEs give an option to open a directory with file manager so it would be pretty straight-forward to do so. Let me know if you have usages other than this. For now, I am keeping this issue open so it can be discussed further if required.

I'd love to see your script though. Would you mind sharing it here?

@Chaitanyabsprip
Copy link
Author

I don't use an IDE, I use neovim, so I don't have direct preview for the assets except for the generated markdown files. Preview in markdown is even though not necessary, it is a nice to have.

My script

import os


def find_files_with_ext(directory: str, ext:str):
    files_with_ext = []
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith(ext):
                files_with_ext.append(os.path.join(root, file))
    return files_with_ext

def generate_line(filename:str):
    hyperlink = f"![](../{filename})"
    line = f"{hyperlink}\n*{filename}*\n"
    return f'{line}\n'


def write_to_output_file(output_file: str, files: list[str]):
    with open(output_file, 'w') as f:
        for filename in files:
            print(filename)
            f.write(generate_line(filename))


def main():
    directory = 'assets'
    svgs_docs = 'docs/svg_assets.md'
    png_docs = 'docs/png_assets.md'
    svgs = find_files_with_ext(directory, '.svg')
    pngs = find_files_with_ext(directory, '.png')
    write_to_output_file(svgs_docs, svgs)
    write_to_output_file(png_docs, pngs)

main()

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

No branches or pull requests

2 participants