承接 harvest-media/craftcms-starter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

harvest-media/craftcms-starter

Composer 安装命令:

composer create-project harvest-media/craftcms-starter

包简介

Harvest Media Craft CMS Starter Package

README 文档

README

This is an opinionated, base starter theme to build new CraftCMS websites at Harvest Media. It's intended to save our developers time and improve consistency across our projects while following good practices for performance.

About CraftCMS

CraftCMS is our tool of choice. It's a flexible, scalable CMS written in PHP (7+), and built on the Yii 2 framework. It can connect to MySQL (5.5+) and PostgreSQL (9.5+) for content storage.

Assumptions

We've designed this starter theme around the most common use cases for Harvest Media including:

  • Hosting on a Linode VPS provisioned by Laravel Forge
    • using the nginx web server
  • Deployed automatically when a user pushes to the master branch

But of course this will work in any other LAMP environment that can run CraftCMS.

Features of this Starter Theme

  • Pages / Navigation (Native Craft Sections)
  • Blog (Native Craft Sections)
  • Content Blocks Builder (Native Craft Matrix)
  • Contact Form (via the Craft Contact Form Plugin)
  • Server Side Static Page Caching (via CacheFlag)
  • CSRF Protection (Native in Craft)
  • SEOMatic (3rd party plugin to keep SEO consistent, easy, and flexible)

Plugin Dependencies

Optional Plugins

Directory Structure

Folders

  • config (for CraftCMS config settings - there should be no client specific information in craft's config folder)
  • modules (used by Craft)
  • vendor (used by npm and ignored in our repo)
  • public (web root)
  • src (source files for front end code: css and js)
  • storage (used by Craft)
  • templates (these are the TWIG template files where we'll be spending most of our development time)
  • translations (used by Craft to change the translation of certain words in the control panel or front end app)
  • vendor (used by Composer and ignored in our repo)

Files

  • .env (Craft's master config file which also contains client-specific information. This will be edited on every single project and different in every environment: dev, staging, and production.)
  • composer.json & composer.lock (Used by Craft - not typically edited manually)
  • craft & craft.bat (Craft's command line files)
  • favicon.master.png (a transparent square logo image that we use to build our favicons here: https://realfavicongenerator.net )
  • package.json &amp package-lock.json (Used by npm - not typically edited manually)
  • README.md (the file we're looking at :-)
  • tailwind.config.js (extends TailwindCSS default configuration to include client brand colors, or other classes.)
  • webpack.mix.js (our Laravel Mix config file that configures SCSS, PostCSS, and JS builds)

Note: This starter theme assumes a directory structure with public as the web root (not "web" or "public_html"). If you change your web root folder name, you will need to update the Laravel Mix config file and Craft's config/general.php file.

Developing for the Front End Using Laravel Mix

Keeping pace with the modern web is challenging, but we make an effort to stay with the pack and follow the recommended practices of the day. Presently, we use Laravel Mix, self-described as an elegant wrapper around Webpack for the 80% use case. Where WebPack configuration is long and complex, Laravel Mix is relatively short and sweet.

See the webpack.mix.js file in the root of the repo.

Developing Locally

From the terminal, cd into the project directory and run npm install.

The follow commands are available. (You can find them in package.json).

  • npm run watch starts a local development with BrowserSync at localhost:3000
  • npm run prod build CSS and JS for production (including PurgeCSS)

Note: that Laravel Mix also supports Hot Module Replacement (HMR) via npm run hot but it seems to be meant for single page javascript apps or .vue files. We've haven't cracked the code on how to use it yet.

See the Laravel Mix config file for details.

CSS (SCSS and PostCSS)

The starter theme has a master CSS file at src/css/theme.scss. It uses:

We include only the pieces of Foundation that we want, rather than the whole framework.

For the most part, styling will happen in the html using tw- utilty classes provided by TailwindCSS.

When building for production SASS/SCSS is processed first, and PostCSS plugins are run afterward.

JS

The master JS file for the theme is located at src/js/theme.js.

For any Foundation plugins that require javascript we included them along with jQuery.

We recommended keeping JS to a minimum.

CSRF Protection with JS

Note: we achieve CSRF protection by the jQuery code.

if (
  $("input[name='CRAFT_CSRF_TOKEN']").length > 0
) {
  $(() => {
    $.ajax({
      url: "/get-token",
      success: response => {
        $("input[name='CRAFT_CSRF_TOKEN']").val(
          response
        );
      }
    });
  });
}

which summarized in English will:

  1. Check for any CSRF form inputs on the page.
  2. Make an AJAX request to a CraftCMS template which contains only the CSRF token.
  3. Add the AJAX response (the current valid CSRF token) to the form inputs.

Templating

Using Macros

Partials, and macros in particular, will help you avoid repetition in your TWIG templates. Use them freely.

SVG Icons

Craft allows us to inline a single SVG in our HTML directly from a file in the public folder. This is much easier than building icon sprites and it allows us to easily include only the icons we actually use on the page.

Here's the code we use to achieve this:

{{ svg('@webroot/assets/svg/YOUR_FILE_NAME_HERE.svg')|attr({class:'YOUR_CLASSES_HERE',role:'img'})|append('<title>YOUR_TITLE_HERE</title>', 'replace') }}

Watching Out for Server Side Performance

Eager loading elements in craft will make a significant difference and is pretty easy to do. See the instructions in Craft's docs.

Local Development and Testing

In addition to testing via the IP address on your network, you can test cross device and remotely (outside your network) by using ngrok.

We also recommend changing the environment from dev to staging when performing final tests locally.

There's More Work to Do on This Starter Theme

Low Hanging Fruit

  • Install the contact form....
  • lazyload images with JS and a macro...

Improve Content Blocks / Builder

harvest-media/craftcms-starter 适用场景与选型建议

harvest-media/craftcms-starter 是一款 基于 Twig 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cms」 「project」 「Craft」 「craftcms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 harvest-media/craftcms-starter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 harvest-media/craftcms-starter 我们能提供哪些服务?
定制开发 / 二次开发

基于 harvest-media/craftcms-starter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Twig

其他信息

  • 授权协议: Unlicense
  • 更新时间: 2021-01-05