记录一下这次搭建Colors小站遇到的问题(为啥总是在不停在踩同一个坑啊‍(╯°口°)╯(┴—┴)

本文分享了关于Vue项目中favicon设置、动态title实现、首次加载速度优化及Nginx配置技巧的经验,包括解决403错误、favicon显示问题、动态设置页面标题、提升加载速度和robots.txt配置。

首先放上小站地址,有兴趣的可以加入呀:Colors小站

1.nginx的403错误

之前一直没遇到过这个问题,使用lsof -I:80的时候,发现nginx一个启动是root,一个是nobody,然后去找原因,果然

进入你的 nginx.conf

添加/修改 user root;

重启 nginx -s reload 搞定

2. vue的favicon设置失败

最开始的时候我以为直接在index.html里面写就可以了

<link rel="shortcut icon" href="./static/favicon/cat.icon" />

结果并不能打包上服务器,无耐寻求万能的互联网。

在运行环境 webpack.dev.conf.js

new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      favicon: './static/favicon/cat.ico', // 添加这个
      inject: true 
}),

在生产环境 webpack.prod.conf.js

new HtmlWebpackPlugin({
      filename: process.env.NODE_ENV === 'testing'
        ? 'index.html'
        : config.build.index,
      template: 'index.html',
      favicon: './static/favicon/cat.ico', // 添加这个
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
        // more options:
        // https://github.com/kangax/html-minifier#options-quick-reference
      },
      // necessary to consistently work with multiple chunks via CommonsChunkPlugin
      chunksSortMode: 'dependency'
}),

然而打包上服务器依然不可以,遂怒,open打包好的index.html,发现favicon的地址不对,改为

之前是<link rel="shortcut icon" href=/cat.ico>改为<link rel="shortcut icon" href="static/favicon/cat.ico">

ok 搞定

3. vue的动态title

如果你不是在一params在路由上传值的话,可以试试这种方式

router.beforeEach((to, from, next) => {
  iView.LoadingBar.start()
  if (to.params.title) {
    document.title = to.params.title
  }
  else if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

4.解决首次访问过慢的问题,加上压缩功能,这个主要是由nginx加上

gzip on;
gzip_http_version 1.1;
gzip_disable 'MSIE[1-6]'; #拒绝ie1-6级压缩
gzip_types text/css text/javascript application/javascript image/jpeg image/png image/gif;
gzip_buffers 4 8k;
gzip_min_length 1k; # 设置最小压缩门槛
gzip_comp_level 9; #压缩级别
gzip_vary on; #加一个head

5.为小站加上robots.txt

re_path(r'^robots\.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),

将robots.txt放在templates下

User-agent: *
Allow:/about
Allow:/article
Disallow:/login
在 OpenSceneGraph (OSG) 中,如果你已经将坐标系沿 **X 轴旋转 -90°**,那么默认的 **Y 轴向上** 的坐标系就变成了 **Z 轴向上** 或者根据你旋转后的逻辑调整。 现在你想在**这个旋转后的坐标系中创建一个三角形并显示在场景中**,你可以通过以下方式实现: --- ## ✅ 实现思路 1. 使用 `osg::Geode` 和 `osg::Geometry` 手动创建一个三角形。 2. 将该三角形添加到一个 `osg::MatrixTransform` 节点中。 3. 该 `MatrixTransform` 对整个子图进行 **X 轴旋转 -90°**,以实现坐标系的转换。 4. 最后将该节点添加到场景图中。 --- ## ✅ 示例代码(C++) ```cpp #include <osg/Geode> #include <osg/Group> #include <osg/Geometry> #include <osg/MatrixTransform> #include <osgViewer/Viewer> // 创建一个三角形 osg::Geode* createTriangle() { osg::Geode* geode = new osg::Geode(); // 创建几何体 osg::Geometry* geom = new osg::Geometry(); // 定义顶点(在 XY 平面) osg::Vec3Array* vertices = new osg::Vec3Array(); vertices->push_back(osg::Vec3(-0.5f, 0.0f, 0.0f)); // 左下 vertices->push_back(osg::Vec3(0.5f, 0.0f, 0.0f)); // 右下 vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.5f)); // 顶部 geom->setVertexArray(vertices); // 定义颜色(红色) osg::Vec4Array* colors = new osg::Vec4Array(); colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); // 添加图元(三角形) geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 3)); // 将几何体添加到 Geode geode->addDrawable(geom); return geode; } int main() { // 创建根节点 osg::Group* root = new osg::Group(); // 创建旋转节点:绕 X 轴旋转 -90 度 osg::MatrixTransform* rotateNode = new osg::MatrixTransform(); rotateNode->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(-90.0f), osg::Vec3(1.0f, 0.0f, 0.0f))); // 创建三角形并添加到旋转节点中 osg::Geode* triangle = createTriangle(); rotateNode->addChild(triangle); // 将旋转节点添加到场景 root->addChild(rotateNode); // 设置相机视角(Y轴向上) osg::Camera* camera = new osg::Camera(); camera->setProjectionMatrix(osg::Matrix::perspective(30.0f, 1.0f, 1.0f, 100.0f)); camera->setViewMatrix(osg::Matrix::lookAt( osg::Vec3(0.0f, -2.0f, 0.0f), // 相机位置 osg::Vec3(0.0f, 0.0f, 0.0f), // 看向原点 osg::Vec3(0.0f, 0.0f, 1.0f) // 上方向为 Z 轴(原坐标系的 Y) )); root->addChild(camera); // 创建 Viewer osgViewer::Viewer viewer; viewer.setSceneData(root); // 运行主循环 return viewer.run(); } ``` --- ## ✅ 代码解释 ### 1. 创建三角形函数 `createTriangle()` - 使用 `osg::Geometry` 手动定义了三个顶点,构成一个三角形。 - 颜色设置为红色。 - 使用 `osg::DrawArrays` 指定这是一个三角形。 ### 2. 旋转节点设置 ```cpp rotateNode->setMatrix(osg::Matrix::rotate(osg::DegreesToRadians(-90.0f), osg::Vec3(1.0f, 0.0f, 0.0f))); ``` - 使用 `osg::MatrixTransform` 将整个子图绕 X 轴旋转 -90°。 - 这样所有添加到该节点下的对象都会自动适配新的坐标系。 ### 3. 添加到场景并设置相机视角 - 使用 `osg::Camera` 自定义相机视角。 - 设置相机在 Y 轴方向观察原点,上方向为 Z 轴(原 Y 轴方向)。 --- ## ✅ 旋转后的坐标系说明 | 原始轴 | 旋转后 | |--------|--------| | X | X | | Y | Z | | Z | -Y | 因此: - **Y 轴向上** - **Z 轴向后** - **X 轴向右** 所以你在创建三角形时,可以将它放在 **XY 平面(即新的 XZ 平面)** 中,它将正确显示在视图中。 --- ## ✅ 注意事项 - 所有对象的位置和方向都应基于旋转后的坐标系。 - 如果你加载模型,可能需要对模型进行坐标系转换。 - 如果你使用物理引擎,也需要同步坐标变换。 --- ##
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值