Import local images to Snap.as
Closed this issue · 1 comments
Feature Overview
When a command-line flag (--images
) is set, the hugo-importer
tool should upload local images to Snap.as and update image links in the source content.
Constraints
This feature is only available to Write.as Pro subscribers. At a minimum, if the --instance
flag is set, the tool should return an error.
There are two main ways to include an image in the source content, and the tool should handle both:
1. Using Markdown (!["Alt text here"](/link/to/image.jpeg)
)
2. Using HTML (<img src="/link/to/image.jpeg" alt="Alt text here" />
)
Implementation
If the --images
flag is set, the tool shall do the following when parsing a source file:
- Search the content of the file for an image (either Markdown or HTML)
- Determine if the image is local or remote (more on this below)
- If image is remote, continue searching; otherwise
- Confirm the image exists in the filesystem at
/static/link/to/image.jpeg
- Upload the image to Snap.as and get the new URL
- Replace the original image source URL with the Snap.as URL
- Continue searching the source file for more images
Image Source: Absolute vs Relative Paths
Related to step 2 in the implementation details above, a local image's source may be represented via an absolute path (https://example.com/link/to/image.jpeg
), or a relative path (/link/to/image.jpeg
). In the latter case, it's clear that the image is local; in the former, however, the tool must determine if the base URL (in this scenario, example.com
) is the URL of the Hugo site being migrated. Fortunately, the baseURL
parameter in the Hugo site configuration file lets us make this comparison.
This looks good to me 👍