So, I created an application using MEAN.js, and made some updates in the section of articles (blog) for better SEO, readability, design, etc. One of the problems that I can't seem to understand is how to share articles using Facebook, Google+, Twitter, etc., and force them to fill in the required data using the og meta tags.
WHAT I WANT
All I want is the ability to publish articles (blog posts) from my MEAN.js app and show the content of the article when I post a link on social sites (like Facebook).
WHAT I ARTED
I tried to create a separate server layout specifically for blog posts, but it violates so many other things that I realized that the amount of work is probably not worth it - there should be a smarter way.
I also tried updating the meta tag data from Angular on the client side, but these values should not be updated before social sites capture these tags ... in other words, it didn’t actually do what I wanted it to be.
I tried to grab the Angular route URL when rendering the index so that I could update this metadata before the index was displayed, but I can not find these values anywhere in the data req.
WHAT I THINK THE PROBLEM
Conceptually, this is what I believe is happening:
The request hits my server, but since it is a one-page application using Angular routing, the value req.urlis just the root page ('/').
An index file is loaded that uses the standard server template template.
Angular AJAX , .
, ( og meta) , Angular , .
express.js :
// Setting application local variables
app.locals.siteName = config.app.siteName;
app.locals.title = config.app.title;
app.locals.description = config.app.description;
app.locals.keywords = config.app.keywords;
app.locals.imageUrl = config.app.imageUrl;
app.locals.facebookAppId = config.facebook.clientID;
app.locals.jsFiles = config.getJavaScriptAssets();
app.locals.cssFiles = config.getCSSAssets();
Swig layout.server.view.html :
// Note the {{keywords}}, {{description}}, etc. values.
<meta id="keywords" name="keywords" content="{{keywords}}">
<meta id="desc" name="description" content="{{description}}">
<meta id="fb-app-id" property="fb:app_id" content="{{facebookAppId}}">
<meta id="fb-site-name" property="og:site_name" content="{{siteName}}">
<meta id="fb-title" property="og:title" content="{{title}}">
<meta id="fb-description" property="og:description" content="{{description}}">
<meta id="fb-url" property="og:url" content="{{url}}">
<meta id="fb-image" property="og:image" content="{{imageUrl}}">
<meta id="fb-type" property="og:type" content="website">
<meta id="twitter-title" name="twitter:title" content="{{title}}">
<meta id="twitter-description" name="twitter:description" content="{{description}}">
<meta id="twitter-url" name="twitter:url" content="{{url}}">
<meta id="twitter-image" name="twitter:image" content="{{imageUrl}}">
, , . , Angular, , , ? , Angular, -, req, , .
, - "" MEAN.js? ? ? , Angular?