-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
185 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,14 @@ jobs: | |
restore-keys: | | ||
${{ runner.os }}-hugomod- | ||
- uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: 'v1.x' | ||
|
||
- run: make fetchdata | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- run: make cibuild | ||
|
||
- name: Deploy to Netlify | ||
|
@@ -61,8 +69,6 @@ jobs: | |
timeout-minutes: 1 | ||
|
||
- run: make cibuild-prod | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Deploy | ||
uses: peaceiris/[email protected] | ||
|
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 @@ | ||
keep this directory |
Binary file not shown.
Binary file not shown.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,108 @@ | ||
import { expandGlobSync } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { | ||
createHash, | ||
SupportedAlgorithm, | ||
} from "https://deno.land/[email protected]/hash/mod.ts"; | ||
import { | ||
Destination, | ||
download, | ||
DownlodedFile, | ||
} from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { exists } from "https://deno.land/[email protected]/fs/mod.ts"; | ||
|
||
class Image { | ||
remoteUrl: string; | ||
remoteUrlHashed: string; | ||
saveDir: string; | ||
extension: string; | ||
|
||
constructor(remoteUrl: string, saveDir: string) { | ||
this.remoteUrl = remoteUrl; | ||
this.remoteUrlHashed = this.hash("sha256", remoteUrl); | ||
this.saveDir = saveDir; | ||
this.extension = this.getExtension(this.remoteUrl); | ||
} | ||
|
||
hash(algorithm: SupportedAlgorithm, str: string): string { | ||
const hash = createHash(`${algorithm}`); | ||
hash.update(str); | ||
return hash.toString(); | ||
} | ||
|
||
getExtension(filename: string) { | ||
return filename.split(".").pop() || ""; | ||
} | ||
|
||
async download() { | ||
const dst: Destination = { | ||
file: `${this.remoteUrlHashed}.${this.extension}`, | ||
dir: this.saveDir, | ||
}; | ||
|
||
if (await exists(`${dst.dir}/${dst.file}`)) { | ||
console.log(`info: skip ${this.remoteUrl}`); | ||
return; | ||
} | ||
|
||
try { | ||
const fileObj: DownlodedFile = await download(this.remoteUrl, dst); | ||
console.log(`info: donwload ${this.remoteUrl} to ${fileObj.fullPath}`); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} | ||
|
||
class Post { | ||
path: string; | ||
images: Array<Image>; | ||
imageSaveDir: string; | ||
|
||
constructor(path: string, imageSaveDir: string) { | ||
this.path = path; | ||
this.images = []; | ||
this.imageSaveDir = imageSaveDir; | ||
} | ||
|
||
async getImageUrls() { | ||
const markdownContent = await Deno.readTextFile(this.path); | ||
// https://docs.github.com/en/github/managing-your-work-on-github/file-attachments-on-issues-and-pull-requests | ||
const regexMarkdownImageLinks = | ||
/https:\/\/user-images.githubusercontent.com\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+\.(png|gif|jpg|jpeg|mp4|mov)/gm; | ||
const matches = markdownContent.match(regexMarkdownImageLinks); | ||
if (matches === null) return; | ||
for (const remoteUrl of matches) { | ||
const image = new Image(remoteUrl, this.imageSaveDir); | ||
this.images.push(image); | ||
} | ||
} | ||
} | ||
|
||
class Blog { | ||
domain: string; | ||
posts: Array<Post>; | ||
imageSaveDir: string; | ||
|
||
constructor(domain: string, imageSaveDir: string) { | ||
this.domain = domain; | ||
this.posts = []; | ||
this.imageSaveDir = imageSaveDir; | ||
} | ||
|
||
getPosts(glob: string) { | ||
for (const file of expandGlobSync(glob)) { | ||
const post = new Post(file.path, this.imageSaveDir); | ||
this.posts.push(post); | ||
} | ||
} | ||
} | ||
|
||
const blog = new Blog("peaceiris.com", "./assets/images"); | ||
await blog.getPosts("./content/**/*.md"); | ||
|
||
for await (const post of blog.posts) { | ||
await post.getImageUrls(); | ||
for await (const image of post.images) { | ||
image.download(); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,28 +1,49 @@ | ||
{{ if .Params.eyecatch }} | ||
{{ $image := resources.Get (printf "%s" ($.Params.eyecatch | safeURL)) }} | ||
{{ $small := $image }} | ||
{{ $medium := $image }} | ||
{{ $large := $image }} | ||
{{ if hugo.IsExtended }} | ||
{{ $small = $image.Resize "480x webp" }} | ||
{{ $medium = $image.Resize "768x webp" }} | ||
{{ $large = $image.Resize "1024x webp" }} | ||
{{ else }} | ||
{{ $small = $image.Resize "480x jpg" }} | ||
{{ $medium = $image.Resize "768x jpg" }} | ||
{{ $large = $image.Resize "1024x jpg" }} | ||
{{ with $.Params.eyecatch }} | ||
|
||
{{ $hashedDestination := sha256 $.Params.eyecatch }} | ||
{{ $extension := path.Ext $.Params.eyecatch }} | ||
{{ $localPath := delimit (slice "images/" $hashedDestination $extension) "" }} | ||
{{ $assetPath := delimit (slice "assets/" $localPath) "" }} | ||
{{ $imagePath := $.Params.eyecatch }} | ||
{{ if (fileExists $assetPath) }} | ||
{{ $imagePath = $localPath }} | ||
{{ end }} | ||
<figure class="image container"> | ||
<picture> | ||
<source media="(max-width: 480px)" srcset="{{ $small.RelPermalink }} 480w"> | ||
<source media="(max-width: 768px)" srcset="{{ $medium.RelPermalink }} 768w"> | ||
<source media="(max-width: 1024px)" srcset="{{ $large.RelPermalink }} 1024w"> | ||
|
||
{{ with resources.Get $imagePath }} | ||
{{ $image := . }} | ||
{{ $small := $image }} | ||
{{ $medium := $image }} | ||
{{ $large := $image }} | ||
{{ if hugo.IsExtended }} | ||
{{ $small = $image.Resize "480x webp" }} | ||
{{ $medium = $image.Resize "768x webp" }} | ||
{{ $large = $image.Resize "1024x webp" }} | ||
{{ else }} | ||
{{ $small = $image.Resize "480x jpg" }} | ||
{{ $medium = $image.Resize "768x jpg" }} | ||
{{ $large = $image.Resize "1024x jpg" }} | ||
{{ end }} | ||
<figure class="image container"> | ||
<picture> | ||
<source media="(max-width: 480px)" srcset="{{ $small.RelPermalink }} 480w"> | ||
<source media="(max-width: 768px)" srcset="{{ $medium.RelPermalink }} 768w"> | ||
<source media="(max-width: 1024px)" srcset="{{ $large.RelPermalink }} 1024w"> | ||
<img | ||
src="{{ $large.RelPermalink }}" | ||
alt="{{ $.Params.Description }}" | ||
decoding="async" | ||
loading="lazy" | ||
/> | ||
</picture> | ||
</figure> | ||
{{ else }} | ||
<figure class="image container"> | ||
<img | ||
src="{{ $large.RelPermalink }}" | ||
src="{{ $imagePath }}" | ||
alt="{{ $.Params.Description }}" | ||
decoding="async" | ||
loading="lazy" | ||
/> | ||
</picture> | ||
</figure> | ||
</figure> | ||
{{ end }} | ||
{{ end }} |
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
Binary file added
BIN
+14.1 KB
...en/images/_hu3797a08418e1e841687b41b638a04d4c_44015_289d90f0bbce840a04c1883fce47d1ad.webp
Binary file not shown.
Binary file added
BIN
+19.5 KB
...en/images/_hu3797a08418e1e841687b41b638a04d4c_44015_931cf52ddcce37f51753a0619255811e.webp
Binary file not shown.
Binary file added
BIN
+8.54 KB
...en/images/_hu3797a08418e1e841687b41b638a04d4c_44015_cc159ddc21c004d67c14b32e2fdf11aa.webp
Binary file not shown.
Empty file.
Binary file added
BIN
+7.67 KB
...en/images/_hue8dde0d9aca7682c524b3650b52d703a_29190_4d2952585d965b6b9468b6445ec29224.webp
Binary file not shown.
Binary file added
BIN
+5.78 KB
...en/images/_hue8dde0d9aca7682c524b3650b52d703a_29190_d56ae032f88adab6f3c1c7899a0014f7.webp
Binary file not shown.
Binary file added
BIN
+3.5 KB
...en/images/_hue8dde0d9aca7682c524b3650b52d703a_29190_ef3530d7a78e0ebbc918a3b9b2e6f7ee.webp
Binary file not shown.