我目前正在尝试为我的一个爱好项目修复元标记,但它目前没有为爬虫呈现元标记。它们来自外部 API 调用,我认为这可能是问题的一部分。
我已经在 index.html 中定义了所有标签,然后我尝试在各种组件中动态更新它们。谁能指出我哪里出错了?这是使用 Angular Universal 运行的。
import { Meta, Title } from '@angular/platform-browser';
...
export class UpcomingPageComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private contentService: ContentService,
private deviceService: DeviceService,
private meta: Meta,
private titleService: Title
) {
this.route.params.subscribe(params => {
this.url_shorthand = params['url_shorthand'];
this.contentService.get_upcoming_title(this.url_shorthand).subscribe(res => {
this.content = res;
this.loaded = true;
this.titleService.setTitle('GameSentry - ' + this.content.title);
this.meta.updateTag({ property: 'og:title', content: 'GameSentry - ' + this.content.title });
this.meta.updateTag({
property: 'og:description', content: 'Monetization & microtransaction info for upcoming game '
+ this.content.title
});
this.meta.updateTag({ property: 'og:image', content: this.content.game_cover });
this.meta.updateTag({ property: 'og:url', content: 'https://gamesentry.com/upcoming/' + this.content.url_shorthand });
this.meta.updateTag({ name: 'twitter:card', content: 'summary' });
});
});
}
...