- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试为爬虫创建动态 og:image 标签以捕获适当的缩略图。我有一个 JS 脚本生成适当的 og:image url,但爬虫在搜索时似乎没有运行任何 JS。有更好的方法吗?
目前:
<head>
<script>
const queryString = window.location.href;
const urlParams = new URLSearchParams(queryString);
const uid = urlParams.get('uid')
const pid = urlParams.get('pid')
if (uid != null && pid != null)
document.getElementById('urlThumb').content = `https://my.app/posts%2F${uid}%2F${pid}%2Furl_thumb.jpg?alt=media`;
</script>
<meta property="og:image" id='urlThumb' content="https://my.app/default%default.png?alt=media"/>
...
</head>
最佳答案
好的,所以我能够以半黑客的方式实现这一目标。我修改了 firebase.json 以将“/post”路由路由到 firebase 云函数。您只需添加要重新路由的路由“源”,并添加要触发的 firebase 云函数的名称。
"rewrites": [
{
"source": "/post",
"function": "prebuildPostPage"
},
{
"source": "**",
"destination": "/index.html"
}
]
我必须添加 'express' 包来处理 https 请求。在您的函数文件夹中运行“npm i express”。然后我做了这两个功能(看起来有点奇怪):
const express = require('express');
const app = express();
app.get('/post', (req, res) => {
console.log(req.query);
const uid = req.query.uid;
const pid = req.query.pid;
console.log(`uid[${uid}], pid[${pid}]`);
if (uid == null || pid == null)
res.status(404).send("Post doesn't exist");
res.send(`<!DOCTYPE html>
<html>
<head>
<meta property="og:image" id='urlThumb' content="${`https://my.app/posts%2F${uid}%2F${pid}%2Furl_thumb.jpg?alt=media`}"/>
<meta property="og:image:width" content="800">
<meta property="og:image:height" content="600">
//Rest is the same as index.js head.
</head>
<body id="app-container">
//Same as index.js body
</body>
</html>
`);
});
exports.prebuildPostPage = functions.https.onRequest(app);
这对于让正确的拇指接触爬虫非常有用,不幸的是它会将人们带到主页。没有布埃诺。
这是因为 Flutter Web 使用“#”来管理页面的路由和历史记录。在转发到我的云功能的 url 中忽略主题标签后的所有内容。
所以...黑客部分...我是我的 flutter web 应用程序 main.dart 文件我必须检查给定的 URL 实际上是否是“my.app/post?uid=xxx&pid=xxx”格式.在这种情况下,我没有加载从主页开始的默认 MyApp,而是创建了一个名为 MyAppPost 的第二个选项,它默认为带有提供的 uid 和 pid 数据的发布屏幕。这行得通,但它搞砸了我的导航系统。
将继续尝试和改进此设置。
void main() {
//Provider.debugCheckInvalidValueType = null;
setupLocator();
String url = window.location.href;
String _uid;
String _pid;
bool isPost = false;
print(url);
if (url.contains('/post')) {
_uid = getParam(url, 'uid', 28);
_pid = getParam(url, 'pid', 20);
if (_uid != null && _pid != null) isPost = true;
}
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => PageManager(),
),
],
child: isPost
? MyAppPost(
uid: _uid,
pid: _pid,
)
: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'VESTIQ',
navigatorKey: locator<NavigationService>().navigatorKey,
onGenerateRoute: (rs) => generateRoute(rs, context),
initialRoute: HomeRoute,
);
}
}
class MyAppPost extends StatelessWidget {
final String uid;
final String pid;
const MyAppPost({Key key, this.uid, this.pid}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'VESTIQ',
navigatorKey: locator<NavigationService>().navigatorKey,
//onGenerateRoute: (rs) => generateRoute(rs, context),
home: PostView(
oid: uid,
pid: pid,
),
);
}
}
编辑:工作导航器
void main() {
setupLocator();
String url = window.location.href;
String _uid;
String _pid;
bool launchWebApp = false;
if (url.contains('/post')) {
_uid = getParam(url, 'uid', 28);
_pid = getParam(url, 'pid', 20);
}
if (url.contains('/app')) launchWebApp = true;
runApp(
MyApp(
uid: _uid,
pid: _pid,
launchWebApp: launchWebApp,
),
);
}
class MyApp extends StatelessWidget {
final String uid;
final String pid;
final bool launchWebApp;
const MyApp({Key key, this.uid, this.pid, this.launchWebApp})
: super(key: key);
@override
Widget build(BuildContext context) {
bool isPostLink = (uid != null && pid != null);
if (isPostLink) {
urlPost = PostCard.fromPost(Post()
..updatePost(
uid: uid,
pid: pid,
));
}
Provider.of<Post>(context, listen: false).updatePost(uid: uid, pid: pid);
return MaterialApp(
title: 'VESTIQ',
navigatorKey: locator<NavigationService>().navigatorKey,
onGenerateRoute: (rs) => generateRoute(rs, context),
initialRoute: launchWebApp
? AppRoute
: isPostLink
? PostRoute
: HomeRoute,
);
}
}
关于javascript - 颤振网络 : SPA: Open Graph: Dynamically assign og:image meta tags,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63364474/
我创建了一个网络应用程序 ( https://www.atalki.com/ ) 并使用 facebook 调试器工具测试该应用程序,以确保 url 在 whatsapp 和其他社交媒体 channe
我们正在使用 Facebook Share Debugger 测试 https://www.roadgoat.com 的开放图标签.我们不断收到错误消息:缺少以下必需属性:og:url、og:type
我已经使用 Nuxt.js 构建了一个 Vue 应用程序,但由于某些原因 og: 标签在 facebook 上不起作用。我在源代码中看到它们,并通过 FB 调试器运行网站,但它说我没有必需的 og:
我的页面上有一个赞按钮。单击按钮时,我试图在 facebook 中发送以下标签信息... 以下是我的点赞按钮框架 下面是动态处理元标签的第一种方法。 var fbTitleTag = ne
我正在即时构建一个图像,以附加到要在 Facebook 上共享的页面。一切似乎都很顺利,直到出现共享对话框。 Facebook 似乎没有抓取,因为图像没有显示。如果我刷新该对话框页面,它会加载图像(从
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
有人可以识别一个网页,其中 和 分享页面的 URL 时实际上是在设置艺术家和专辑吗? 我一直在敲http://www.coises.com/songs/sfcarol.htm几个小时,尝试 META
我的网站上有一个页面,位于:www.mywebsite.com/share/id该网站有以下标签: 该页面有一个 achor 标签,其中包含指向 http://www.f
我正在尝试使用 share_open_graph 设置动态共享到 Facebook 的 og 值方法: FB.ui({ method: 'share_open_graph',
有人可以建议为什么 FB 调试/lint 工具说 og:type 是“网站”,尽管 og:type 被设置为 og:bar? https://developers.facebook.com/tools
一段时间以来,我一直在系统地使用双斜线、协议(protocol)无关的 URL 版本,在 HTML 中(用于 anchor 上的 href 和 src 在图像上)和在 JS 中(对于 XHR)。今天我
我对 og 有疑问:键入 facebook。我已经将 meta og: type 设置为“article”,但仍然检测到 og: type 是“website”。但是,每次我尝试再次抓取时,og: t
GlassFish ogs-3.1.2.2-windows.exe 和 ogs-3.1.2.2-windows-ml 之间有什么区别>.exe [1] 文件? [1] : http://www.ora
浏览youtube视频时,我看到了一些奇怪的东西。随着我不断从一页浏览到另一页,og:image不会改变。 og:image始终指向第一个youtube视频。当然,如果手动刷新页面,则会看到正确的og
我正在构建一个应该为用户使用openGraph对象的iOS应用。 如我所见,我需要: 1. 为这些对象中的每个对象创建对象页面,这些页面包含facebook为中的已创建对象生成的所有元标记Get Co
我对使用 -oG 选项的 masscan 实用程序生成的输出(“grep-able”输出)有疑问;例如,它输出: # Masscan 1.0.3 scan initiated Wed Jun 4 0
我们正在使用flume,我需要将一些日志消息收集到rabbitmq 中。我找到了一个来源 implementation从rabbitmq读取消息,但我找不到可以将消息写入rabbit的接收器。所以我想
我正在使用 Facebook 发送按钮,并将以下内容放在显示发送按钮的页面上: 编辑:我在页面的 html 部分的顶部添加了代码: 编辑:我在发送按钮代码下方添加:
我创建了一个带有订阅功能的 Facebook 应用程序。 当用户打开应用程序时,有一个名为“订阅”的按钮。单击该按钮时,将调用 javascript 函数completePayment()。出现订阅的
我已经正确添加了所有og:meta标签,并且Facebook调试器正确抓取。我唯一的问题是,从我们的网站共享时,视频的缩略图会被裁剪,但如果从YouTube共享,则会完美。 我们的META:
我是一名优秀的程序员,十分优秀!