0

I need to point my og:url tag to a longer-lived page two levels up. I am writing my views in a jade/pug template.

The tag for the page in question should be:

meta(property="og:url" content="http://www.example.com/cat/tabby/tagNumber/59c27/../..")

which is equivalent to

meta(property="og:url" content="http://www.example.com/cat/tabby")

But my pages are dynamic, and I do not know the best way to specify the url. I really want to be able to do something neat like:

meta(property="og:url" content="./../..")

But that is wrong according to the OG spec, and ignored by the facebook crawler.

Is there a way to do something more like this:

meta(property="og:url" content= thisVarURL +"/../..")

Without modifying my controller functions to send a url variable to my view.

furt furt
  • 121
  • 1
  • 8

1 Answers1

0

I don't believe there is an automated way of doing this, but you can certainly pass an environment variable thisVarURL to each view, and assign it the URL value. If you want a more elegant way of doing it, I suggest combining the middleware approach outlined in this question with the retrieving of a request's URL through the snippet given in this question.

No idea if this works, but it could look something like this:

app.use(function locals(req, res, next) {
    res.locals.thisVarURL = req.protocol + '://' + req.get('host') + req.originalUrl;
    next();
});
gandreadis
  • 3,004
  • 2
  • 26
  • 38