-
Notifications
You must be signed in to change notification settings - Fork 52
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
Autogenerate project preview images for Open Graph #1886
base: main
Are you sure you want to change the base?
Conversation
Handler triggers a generate thumnail method using the html2image module. - CSS styling to the added to the template. - Project models needs a new column for BYTEA data - A method to add the generated image to the new BYTEA column needs to be added - Cache headers have to be set in the view to tell Nginx to the cache the date
for more information, see https://pre-commit.ci
-Ran db migration -Generate thumbnail method writes png to the db
…nto auto-thumbnails
for more information, see https://pre-commit.ci
…nto auto-thumbnails
Configured precommit to run locally
for more information, see https://pre-commit.ci
…nt to serve image from project view
for more information, see https://pre-commit.ci
text-align: left; | ||
display: flex; | ||
justify-content: space-between; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move these to a new preview.scss
file under assets/sass/pages
var gradient = 'linear-gradient(to bottom right, hsl('+ huePair[0] +', 100%, 87%), hsl('+ (huePair[0]+(huePair[1]-huePair[0])*0.33) +', 100%, 87%), hsl('+ (huePair[0]+(huePair[1]-huePair[0])*0.66) +', 100%, 87%), hsl('+ huePair[1] +', 100%, 87%))'; | ||
console.log(gradient); | ||
document.getElementById("container").style.background = gradient; | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same. Move the JS part to a new preview.js file under assets/js. Include it in webpack.config.js
window.addEventListener("load", () => { | ||
var hueValues = [5, 23, 39, 48, 92, 172, 201, 220, 273, 335] | ||
huePair = randomizeElements(hueValues, 2); | ||
var gradient = 'linear-gradient(to bottom right, hsl('+ huePair[0] +', 100%, 87%), hsl('+ (huePair[0]+(huePair[1]-huePair[0])*0.33) +', 100%, 87%), hsl('+ (huePair[0]+(huePair[1]-huePair[0])*0.66) +', 100%, 87%), hsl('+ huePair[1] +', 100%, 87%))'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use template string here
gradient = linear-gradient(to bottom right, hsl(${huePair[0]}, 100%, 87%)....
|
||
window.addEventListener("load", () => { | ||
var hueValues = [5, 23, 39, 48, 92, 172, 201, 220, 273, 335] | ||
huePair = randomizeElements(hueValues, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is 2 being sent to. randomizeElements. Function expects just one parameter
result.push(element); | ||
} | ||
return result; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set doesn't allow duplicate
This can be simplified
const randomizeElements = (hueList) => {
const uniqueHuePair = new Set();
let hueCount = array.length;
let randomIndex;
let hue;
while (randomSelection.size < 2) {
randomIndex = randomizeIndex(hueCount);
hue = hueList[randomIndex];
uniqueHuePair.add(hue);
}
return uniqueHuePair;
};
var [hueValue1, hueValue2] = randomizeElements(hueValues)
…after function call
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Handler triggers a generate thumnail method using the html2image module.