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

Add option to automatically download the generated images #6

Open
dsebastien opened this issue Aug 19, 2024 · 1 comment
Open

Add option to automatically download the generated images #6

dsebastien opened this issue Aug 19, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@dsebastien
Copy link
Owner

Goal: directly save the generated images locally

@dsebastien dsebastien added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Aug 19, 2024
@dsebastien
Copy link
Owner Author

Download image:

export async function downloadImage(url: string): Promise<ArrayBuffer> {
  const res = await got(url, { responseType: "buffer" });
  return res.body;
}

Clean file name:

export const FORBIDDEN_SYMBOLS_FILENAME_PATTERN = /\s+/g;

export function cleanFileName(name: string) {
  const cleanedName = filenamify(name).replace(
    FORBIDDEN_SYMBOLS_FILENAME_PATTERN,
    "_"
  );
  return cleanedName;
}

Create image tag:

function createImageTag(anchor: string, link: string) {
  return `![${anchor}](${link})`;
}

Reference: https://github.com/aleksey-rezvov/obsidian-local-images/tree/master/src

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant