Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Удаляет этап генерации карточек для социальных сетей #1321

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/product-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
run: |
cp .env.example .env
npm run build
- name: Генерация карточек для социальных сетей
run: npx gulp socialCards
- name: Публикация сайта
run: |
cd dist
Expand Down
61 changes: 0 additions & 61 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
const path = require('path')
const fs = require('fs')
const fsp = require('fs/promises')
const { Transform } = require('stream')
const { pipeline } = require('stream/promises')

const gulp = require('gulp')
const git = require('gulp-git')
Expand All @@ -16,7 +13,6 @@ const esbuild = require('gulp-esbuild')
const del = require('del')
const rev = require('gulp-rev')
const revRewrite = require('gulp-rev-rewrite')
const puppeteer = require('puppeteer')

const { contentRepGithub, contentRepFolders } = require(path.join(__dirname, 'config/constants'))

Expand Down Expand Up @@ -123,62 +119,5 @@ exports.setupContent = gulp.series(cloneContent, makeLinks)

exports.dropContent = () => del(['content', ...contentRepFolders.map((folder) => `src/${folder}`)])

// Social cards

const socialCards = async () => {
const browser = await puppeteer.launch({ headless: 'new' })
const page = await browser.newPage()

return pipeline(
gulp.src('dist/{a11y,css,html,js,tools,recipes}/**/index.sc.html'),
new Transform({
objectMode: true,
async transform(file, encoding, done) {
const imagePath = file.path.replace('index.sc.html', 'images/covers/')
if (!fs.existsSync(imagePath)) {
await fsp.mkdir(imagePath, { recursive: true })
}

await page.goto('file://' + file.path)

await page.evaluate(() => {
const image = document.querySelector('.social-card__image')
if (image) {
image.setAttribute('src', image.src.replace(/.*images\//, 'images/'))
}
})

await page.setViewport({
width: 503,
height: 273,
deviceScaleFactor: 1,
})

await page.screenshot({
path: path.join(imagePath, 'og.png'),
type: 'png',
clip: {
x: 0,
y: 0,
width: 503,
height: 273,
},
})

done()
},
}),
)
.catch(console.error)
.finally(async () => {
await page.close()
await browser.close()
})
}

// Build social cards

exports.socialCards = socialCards

// Default
exports.default = gulp.series(clean, styles, scripts, sw, cache)
Loading
Loading