generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from BoyWithSilverWings/feature/component
Feature/component
- Loading branch information
Showing
14 changed files
with
209 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: "Run tests" | ||
on: [pull_request, push] | ||
|
||
jobs: | ||
check_pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: "npm ci" | ||
run: npm ci | ||
|
||
- name: "npm run build" | ||
run: npm run build | ||
|
||
- name: "npm run test" | ||
run: npm run test | ||
|
||
- name: "check for uncommitted changes" | ||
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed. | ||
run: | | ||
git diff --exit-code --stat -- . ':!node_modules' \ | ||
|| (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \ | ||
"and check in all changes" \ | ||
&& exit 1) |
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 |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
Generates open graph images for your blog with Github Actions. | ||
|
||
This github action scans your PR for changes to `md` or `mdx` files, reads frontmatter configuration from them and generates images for your SEO. | ||
|
||
In your action file: | ||
|
||
```yml | ||
name: "Generate OG Images" | ||
on: pull_request | ||
|
@@ -26,18 +30,52 @@ For configuring the parameters, add following fields to the frontmatter: | |
```md | ||
--- | ||
title: "Things you don't know about something 2019" | ||
ogImage: | ||
title: "Things you don't know" | ||
subtitle: "There must be something" | ||
imageUrl: "https://example.com/image-url.jpg" | ||
background-color: "yellow" | ||
font-color: "rgb(0, 0, 0)" | ||
background: "yellow" | ||
fontColor: "rgb(0, 0, 0)" | ||
fontSize: "100%" | ||
--- | ||
``` | ||
|
||
## Frontmatter Props | ||
|
||
| Props | Description | Required | | ||
| ---------- | :-------------------------------------: | -------: | | ||
| title | Title of the image | | | ||
| subtitle | Subtitle of the image | | | ||
| imageUrl | The image thumbnail on the top | | | ||
| background | Background color, gradient or image url | | | ||
| fontColor | any css supported color | | | ||
| fontSize | the font size | | | ||
|
||
Works only with Pull Requests and `md` and `mdx` files. | ||
|
||
## Repository level Props | ||
|
||
These are props that you can configure in the action file to customise the working. | ||
|
||
| Props | Description | Required | | ||
| ------------ | :--------------------------------------: | -------: | | ||
| path | Path to place the image URL in | true | | ||
| commitMsg | Commit message when image is added | | | ||
| background | Background color, gradient or image url | | | ||
| fontColor | any css supported color | | | ||
| fontSize | the font size | | | ||
| componentUrl | Web Component to be rendered for output. | | | ||
|
||
Frontmatter level props on a document always takes precedence over Repository level props. | ||
|
||
### I need more customisation on the output. | ||
|
||
The generator uses a web component to create the default output and provides a repository level prop to customise this web component. | ||
|
||
The component currently being used is on [Github](https://github.com/BoyWithSilverWings/og-image-element) and published on [NPM](https://www.npmjs.com/package/@agney/og-image-element). The default URL is from [Unpkg](https://unpkg.com/) with [https://unpkg.com/@agney/[email protected]](https://unpkg.com/@agney/[email protected]). | ||
|
||
You can substitute the same with `componentUrl` input in your workflow file. For more info on creating this web component, visit [source](https://github.com/BoyWithSilverWings/generate-og-image/blob/304fd9aa0b21b01b0fdc8a3d1a63a19ffdc1840d/demo/test-file.jpg) | ||
|
||
## Thanks | ||
|
||
1. [Zeit OG Image](https://github.com/zeit/og-image) | ||
|
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 @@ | ||
import generateHtml from "../src/generate-html"; | ||
|
||
describe("Generate HTML", () => { | ||
it(`returns a string`, () => { | ||
const result = generateHtml({}); | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it(`contains background variable`, () => { | ||
const result = generateHtml({ | ||
background: "{{name}}" | ||
}); | ||
expect(result.includes("--background")).toBe(true); | ||
}); | ||
|
||
it(`contains font color variable`, () => { | ||
const result = generateHtml({ | ||
fontColor: "{{name}}" | ||
}); | ||
expect(result.includes("--fontColor")).toBe(true); | ||
}); | ||
|
||
it(`contains font size variable`, () => { | ||
const result = generateHtml({ | ||
fontSize: "{{name}}" | ||
}); | ||
expect(result.includes("--fontSize")).toBe(true); | ||
}); | ||
|
||
it(`contains passed in title`, () => { | ||
const result = generateHtml({ | ||
title: `{{name}}` | ||
}); | ||
expect(result.includes("{{name}}")).toBe(true); | ||
expect(result.includes(`slot="title"`)).toBe(true); | ||
}); | ||
|
||
it(`creates large payload`, () => { | ||
const result = generateHtml({ | ||
assetPath: "demo/", | ||
componentUrl: "https://unpkg.com/@agney/[email protected]", | ||
commitMsg: "just some wholesome content. yo all!", | ||
background: "red", | ||
fontColor: "yellow", | ||
fontSize: "90%", | ||
title: "Generating open graph images with Github Actions", | ||
subtitle: "Works with Markdown files", | ||
imageUrl: "https://avatars3.githubusercontent.com/u/8883368?s=40&v=4" | ||
}); | ||
console.log(result); | ||
expect(true).toBe(true); | ||
}); | ||
}); |
This file was deleted.
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 |
---|---|---|
|
@@ -11,12 +11,24 @@ inputs: | |
commitMsg: | ||
description: "commit message to be shown when adding image" | ||
default: "just some wholesome content. yo all!" | ||
background-color: | ||
background: | ||
description: "background color for image" | ||
default: "#ffffff" | ||
font-color: | ||
fontColor: | ||
description: "font color for image" | ||
default: "#000000" | ||
componentUrl: | ||
description: "URL for web component" | ||
default: "https://unpkg.com/@agney/[email protected]" | ||
fontSize: | ||
description: "Font size for the root" | ||
default: "100%" | ||
width: | ||
description: "Width of the screen" | ||
default: "1200" | ||
height: | ||
description: "Height of the screen" | ||
default: "630" | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,35 +1,41 @@ | ||
import { IProps } from "./types"; | ||
import { debug } from "@actions/core"; | ||
import { IRepoProps } from "./types"; | ||
|
||
function generateHtml(prop: Partial<IProps>) { | ||
debug(JSON.stringify(prop)); | ||
function createVariables(name: string, value?: string) { | ||
if (value) { | ||
return `--${name}: ${value};`; | ||
} | ||
return ""; | ||
} | ||
|
||
function generateHtml(prop: Partial<IRepoProps>) { | ||
return ` | ||
<!doctype html> | ||
<html lang="en-GB"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<link href="https://fonts.googleapis.com/css?family=Aleo|Open+Sans&display=swap" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/css?family=Nunito:600|Open+Sans&display=swap" rel="stylesheet"> | ||
<style> | ||
body { | ||
margin: 0; | ||
font-family: 'Open Sans', sans-serif; | ||
} | ||
og-image-element { | ||
--heading-font: 'Aleo', serif; | ||
--background-color: ${prop.backgroundColor}; | ||
--font-color: ${prop.fontColor}; | ||
--heading-font: 'Nunito', serif; | ||
${createVariables("fontColor", prop.fontColor)} | ||
${createVariables("background", prop.background)} | ||
${createVariables("fontSize", prop.fontSize)} | ||
} | ||
</style> | ||
<script type="module" rel="preload" src="https://unpkg.com/@agney/[email protected]"></script> | ||
<script type="module" rel="preload" src="${prop.componentUrl}"></script> | ||
</head> | ||
<body> | ||
<og-image-element subtitle=${prop.subtitle || ""}> | ||
<og-image-element subtitle="${prop.subtitle || ""}"> | ||
${ | ||
prop.imageUrl | ||
? `<img slot="image" src="${prop.imageUrl}" height="100%" />` | ||
: `` | ||
} | ||
<div slot="title">${prop.title}</div> | ||
<div slot="title">${prop.title || ""}</div> | ||
</og-image-element> | ||
</body> | ||
</html> | ||
|
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
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