-
Notifications
You must be signed in to change notification settings - Fork 368
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding FigmaImage component and script
- Loading branch information
1 parent
2fd468c
commit d36f81c
Showing
6 changed files
with
877 additions
and
1,187 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 |
---|---|---|
|
@@ -2,23 +2,40 @@ name: Get Figma Images | |
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
# branches: | ||
# - main | ||
|
||
jobs: | ||
findNodeReferences: | ||
runs-on: ubuntu-latest | ||
env: | ||
FilesToScan: '**/*.mdx' | ||
ImageUrlFile: figmaImageNodeUrls.json | ||
ImageOutputDir: content/images/figma | ||
FigmaToken: ${{ secrets.FIGMA_TOKEN }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
cache: 'yarn' | ||
- name: Install dependencies | ||
run: npm ci --no-audit --no-fund --include=dev --ignore-scripts | ||
run: yarn | ||
- name: Get Figma Images | ||
run: node scripts/getFigmaImages.js '**/*.mdx' > figmaImageNodeUrls.json | ||
run: node scripts/getFigmaImages.js "${{env.FilesToScan}}" > ${{env.ImageUrlFile}} | ||
- name: Log file content | ||
run: cat figmaImageNodeUrls.json | ||
run: cat ${{env.ImageUrlFile}} | ||
- name: Download images from figma | ||
run: npx @primer/figma-images --figmaToken ${{env.FigmaToken}} --nodeURLsFile ${{env.ImageUrlFile}} --outputDir ${{env.ImageOutputDir}} | ||
- name: Log output dir content | ||
run: ls ${{env.ImageOutputDir}} | ||
- name: Add images to repo | ||
run: | | ||
git config --global user.name 'Figma Images Action' | ||
git config --global user.email '[email protected]' | ||
git add -A ${{env.ImageOutputDir}} | ||
git commit -m "Update Figma images" | ||
git push | ||
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import {parseFigmaNodeUrl} from '@primer/figma-images/src/utils'; | ||
|
||
type FigmaImageProps = React.ImgHTMLAttributes<HTMLImageElement> & { | ||
src: string | ||
} | ||
|
||
const FigmaImageDir = 'content/images/figma'; | ||
|
||
export const FigmaImage: React.FC<FigmaImageProps> = ({src, ...props}) => { | ||
// check for missing prop | ||
if(src === undefined) throw new Error("src is required on FigmaImage component"); | ||
// get real image url | ||
const {nodeId, fileId} = parseFigmaNodeUrl(src); | ||
const imagePath = `${FigmaImageDir}/${fileId}-${nodeId}.png` | ||
// return image component | ||
return (<img src={imagePath} {...props}/><Link href={src}>Edit Image</Link>) | ||
} |
Oops, something went wrong.