几周前,我在我的计算机上全局安装了 NestJS。现在我回到这个话题,开始学习。
所以我用命令创建了新项目:
nest new ./
Run Code Online (Sandbox Code Playgroud)
它生成了所有文件,但是当我尝试使用命令运行该应用程序时:
nest start
Run Code Online (Sandbox Code Playgroud)
我预计该模板项目会启动,但导入路径有错误?这是由于我安装的 Nest 版本还是其他原因造成的?
我的巢版本:
7.5.6
包.json:
"dependencies": {
"@nestjs/common": "^7.6.13",
"@nestjs/core": "^7.6.13",
"@nestjs/platform-express": "^7.6.13",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^6.6.6"
},
"devDependencies": {
"@nestjs/cli": "^7.5.6",
"@nestjs/schematics": "^7.2.7",
"@nestjs/testing": "^7.6.13",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@types/supertest": "^2.0.10",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"supertest": "^6.1.3",
"ts-jest": "^26.5.2",
"ts-loader": "^8.0.17",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.5"
},
Run Code Online (Sandbox Code Playgroud) 基本上我想要实现的是在链接缩略图上显示主要博客文章图像,同时在 Twitter、Facebook 等社交媒体上分享它。
我所拥有的元标记<Helmet>已添加到网站中,但它们不正确,或者不符合我在共享链接时所期望的读取方式。我认为这是因为此时尚未填充这些值。但如何解决呢?或者说实现这一目标的正确方法是什么?
以下是我尝试在组件中注入元标记的方法:
<Helmet>
<meta property="og:type" content="website"/>
<meta property="og:url" content={`https://blackh3art.dev/blog/${slug}`}/>
<meta property="og:title" content={title}/>
<meta property="og:description" content={short} />
<meta property="og:image" content={formatedimage}/>
<meta property="twitter:card" content="summary_large_image"/>
<meta property="twitter:url" content={`https://blackh3art.dev/blog/${slug}`}/>
<meta property="twitter:title" content={title}/>
<meta property="twitter:description" content={short} />
<meta property="twitter:image" content={formatedimage}/>
</Helmet>
Run Code Online (Sandbox Code Playgroud)
但在任何地方我会尝试在我的组件中注入元标记,但它不起作用。唯一有效的元标记是我在我的 中静态声明的元标记index.html,并且图像从我的网站读取到每个链接。
现在应用程序正在以这种方式工作:
<BlogPostPage/>组件正在从上下文中获取所有数据网站已经部署,因此您可以查看是否需要: