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

Autogenerate project preview images for Open Graph #1886

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

anishTP
Copy link
Contributor

@anishTP anishTP commented Sep 28, 2023

Handler triggers a generate thumnail method using the html2image module.

  • CSS styling to be added to the template.
  • Project model 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

anishTP and others added 12 commits September 28, 2023 12:34
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
-Ran db migration
-Generate thumbnail method writes png to the db
Configured precommit to run locally
@anishTP anishTP marked this pull request as ready for review October 12, 2023 06:45
@jace jace changed the title Added signals and handler for project data change Autogenerate project preview images for Open Graph Nov 6, 2023
text-align: left;
display: flex;
justify-content: space-between;
}
Copy link
Member

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;
})
Copy link
Member

@vidya-ram vidya-ram Nov 8, 2023

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%))';
Copy link
Member

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);
Copy link
Member

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;
};
Copy link
Member

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants