-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic logic for exporting all images that are referenced in markdown images (![alt](../assets/image.png))
- Loading branch information
Showing
5 changed files
with
175 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
) | ||
|
||
func readFileToString(src string) (string, error) { | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer srcFile.Close() | ||
bytes, err := os.ReadFile(src) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(bytes), nil | ||
} | ||
|
||
func writeStringToFile(dest string, content string) error { | ||
err := os.WriteFile(dest, []byte(content), os.ModePerm) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func copy(src, dest string) error { | ||
srcFile, err := os.Open(src) | ||
if err != nil { | ||
return err | ||
} | ||
defer srcFile.Close() | ||
|
||
destFile, err := os.Create(dest) // creates if file doesn't exist | ||
if err != nil { | ||
return err | ||
} | ||
defer destFile.Close() | ||
|
||
_, err = io.Copy(destFile, srcFile) // check first var for number of bytes copied | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = destFile.Sync() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters