node.js 制作网站(nodejs制作网站)

时间: 2022-09-10 09:53:43 浏览次数:318

《开源精选》是我们分享Github、Gitee等开源社区中优质项目的栏目,包括技术、学习、实用与各种有趣的内容。本期推荐的 Ghost 是一个基于现代 Node.js 技术堆栈的开源专业发布平台。

Ghost 是一个基于现代 Node.js 技术堆栈的开源专业发布平台,专为需要强大功能、灵活性和性能的团队而设计。

Ghost特征

特别快

?

?

?

可靠安全

?

?

?

很棒的设计

?

?

?

现代科技

?

?

?

开源

?

?

?

拥有你的品牌+数据

?

?

?

使用自定义域

?

?

?

控制您的网站设计

?

?

?

免审查

?

?

?

内置 SEO 控制

?

?

?

原生 REST API

?

?

?

综合SDK

?

?

?

内置会员和订阅
商务功能

?

?

?

适用于任何前端
或静态网站框架

?

?

?

如何安装Ghost

最快的入门方法是在Ghost(Pro)上建立一个站点。如果您正在运行自托管实例,我们强烈建议您使用至少 1GB 内存的 Ubuntu 服务器来运行 Ghost。

本地安装 Ghost

Ghost-CLI是一个命令行工具,可帮助您快速轻松地安装和配置 Ghost 以供使用。npm 模块可以安装在本地计算机上,npm也可以安装yarn在本地计算机上,具体取决于您的偏好。

npm install ghost-cli@latest -g

安装后,您始终可以运行ghost help以查看可用命令的列表。

在您的终端中,cd进入一个空目录并运行安装命令:

ghost install local

安装完成后,您将能够访问您的新站点http://localhost:2368并http://localhost:2368/ghost访问 Ghost Admin。

启动和停止

Ghost 在单独的后台进程中运行并一直运行,直到您停止它或重新启动计算机。所以你可能会发现这些命令对使用它很有用:

  • ghost stop 停止ghost
  • ghost start 启动ghost
  • ghost log 查看日志
  • ghost ls 列出所有正在运行的 Ghost 博客

使用 GScan 进行验证

GScan 是一个验证 Ghost 主题是否与最新版本的 Ghost 兼容的工具。当主题被上传或激活时,Ghost 会自动运行这个工具。出于开发目的,您也可以通过在本地安装它自己运行这些检查。

# Install gscan globally
npm install gscan -g

# Scan a theme directory for compatibility
gscan /path/to/ghost/content/themes/casper

# Scan a theme zip file for compatibility
gscan -z /path/to/downloads/theme.zip

从源代码安装 Ghost

首先创建 GitHub 分支:首先,您需要创建Ghost和Ghost-Admin存储库的分支。单击顶部右侧的 fork 按钮,等待在您的个人 GitHub 帐户上创建副本。

下一步是为本地开发配置 Git 存储库:主 Ghost 存储库包含完整的 Ghost 包,包括管理客户端和默认主题,它们也将自动设置

# First clone Ghost with submodules and make it your working dir
git clone --recurse-submodules git@github.com:TryGhost/Ghost && cd Ghost

重命名

# Rename origin to upstream
git remote rename origin upstream

# Add your fork as an origin, editing in <YourUsername>!
git remote add origin git@github.com:<YourUsername>/Ghost.git

因为 Ghost-Admin 是 Ghost 主存储库的子模块存储库,所以这里也需要重复相同的步骤来配置 Git。

# Switch to Ghost-Admin dir
cd core/admin

更新 Ghost-Admin

# Quick check that everything is on latest
git checkout main && git pull upstream main

# Then return to Ghost root directory
cd ../../

运行设置和安装

# Only ever run this once
yarn setup

该setup任务将安装依赖项、初始化数据库、设置 git 挂钩和初始化子模块并运行管理员的第一个构建。

测试

服务器测试

使用 SQlite 运行测试。要使用 MySQL,请在命令前添加NODE_ENV=testing-mysql

yarn test:unit
# Run unit tests

yarn test:acceptance
# Run acceptance tests

yarn test:regression
# Run regression tests

yarn test path/to/test.js
# Run a single test

yarn test test/unit/helpers
# Run a folder of tests

yarn test:all
# Run all tests

yarn lint
# Make sure your code doesn't suck

客户端测试

客户端测试应始终在core/admin目录内运行。任何时候yarn dev运行客户端测试都可以在http://localhost:4200/tests

ember test
# Run all tests in Chrome + Firefox

ember test --server
# Run all tests, leave results open, and watch for changes

ember test -f 'gh-my-component'
# Run tests where `describe()` or `it()` matches supplied argument
# Note: Case sensitive

ember test --launch=chrome
# Run all tests in Chrome only

ember test -s -f 'Acceptance: Settings - General' --launch=chrome
# Most useful test comment for continuous local development
# Targets specific test of area being worked on
# Only using Chrome to keep resource usage minimal

故障排除

ERROR: (EADDRINUSE) 无法启动 Ghost

此错误表示 Ghost 已在运行,您需要停止它。

ERROR: ENOENT

这个错误意味着提到的文件不存在。

ERROR 错误:找不到模块

安装未完成。运行yarn:fix。

错误:找不到模块“./build/default/DTraceProviderBindings”

您切换了节点版本。运行yarn:fix。

ENOENT:没有这样的文件或目录,在错误(本机)处显示 'path/to/favicon.ico'

您的管理客户端尚未构建。运行yarn dev。

TypeError: Cannot read property 'tagName' of undefined

你不能同时ember test运行yarn dev。在继续之前等待测试完成,并在加载管理员之前等待“构建成功”消息。

主题开发

Ghost 主题使用 Handlebars 模板语言,该语言使用帮助程序在模板(HTML)和任何 JavaScript 逻辑之间建立了强大的分离。这允许主题非常快,具有动态客户端应用程序,以及作为静态 HTML 发送到浏览器的服务器端发布内容。

Ghost 还使用了一个名为的附加库,该库express-hbs为 Handlebars 添加了一些附加功能,例如布局和局部。

如果您以前为其他流行平台构建过主题,那么使用 Ghost 主题层非常容易。本文档为您提供了为主题创建静态 HTML 和 CSS 所需的工具,在您需要呈现动态数据时使用 Handlebars 表达式。
要将 GScan 用作命令行工具,请全局安装gscannpm 包:

# Install the npm package
npm install -g gscan

# Use gscan <file path> anywhere to run gscan against a folder
gscan /path/to/ghost/content/themes/casper

# Run gscan on a zip file
gscan -z /path/to/download/theme.zip

主题推荐

—END—

开源协议:MIT license

开源地址:https://github.com/TryGhost/Ghost

  非常感谢您读完蓝港网络的这篇文章:"node.js 制作网站(nodejs制作网站)",仅为提供更多信息供用户参考使用或为学习交流的方便。我们公司提供:网站建设、网站制作、官网建设、SEO优化、小程序制作等服务,欢迎联系我们提供您的需求。

标签: in me

Copyright © 常州蓝港网络科技有限公司 苏ICP备2022017479号-1