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

fix: #7444 Re-factor handling of og:image tags #7463

Merged
merged 10 commits into from
Mar 18, 2019
Merged

Conversation

julianlam
Copy link
Member

@julianlam julianlam commented Mar 16, 2019

The new logic will supply og:image tags in the following order:

  1. All uploaded images in a post (or if no post selected via index, then OP)
  2. Topic thumbnail if set
  3. The category background image if set
  4. Poster avatar if set
  5. Global og:image if set in ACP, otherwise, brand:logo if set in ACP, otherwise /logo.png

A provided upgrade script will calculate sizes for all uploads tracked in NodeBB (if they're associated with a post, that is), and will then insert the appropriate og:image:height and og:image:width tags.

// Returns array of this post's uploads
db.getSortedSetRange('post:' + pid + ':uploads', 0, -1, callback);
};

Posts.uploads.listWithSizes = async function (pid) {
const paths = await Posts.async.uploads.list(pid);
const sizes = await db.getObjects(paths.map(path => 'upload:' + md5(path)));
const sizes = await db.async.getObjects(paths.map(path => 'upload:' + md5(path)));
Copy link
Member Author

@julianlam julianlam Mar 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@barisusakli I experienced an issue here. If at top of file I require('../database').async, then later on in the file, console.log(db); was undefined if called from inside Posts.upload.list.

I ended up fixing it by doing db.async when used inside the file instead.

Just to give you some context, the upgrade script I was writing was calling await Posts.uploads.list(), and erroring out as db was undefined.

@julianlam julianlam merged commit 697a659 into master Mar 18, 2019
@julianlam julianlam deleted the og-image-refactor branch April 27, 2020 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant