A
A
Alex2020-10-04 17:12:58
Node.js
Alex, 2020-10-04 17:12:58

How not to skip css class in commit?

There is a simple project. Written in 11ty. It uses the Nunjucks template engine.
The essence of the problem: sometimes for debugging in one specific file for one specific html element, a class is added. But it is very important that this class does not get into the production and be deleted before the commit.

How can this be resolved? Use an html validator and somehow implement your own rules into it? Or use some kind of framework for tests and already inside it parse html and check it yourself? And what is customary to check in such cases: the file with the source code, or the final html?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aleksey Solovyev, 2020-10-05
@Kozack

Perhaps I misunderstand the task, but what prevents you from passing a variable to Nunjucks and using it for conditional rendering?
What I mean: WebPack
example : nunjucks.config.js

module.exports = {
  data: {
    isDev: process.env.NODE_ENV === 'development'
  }
}

template.njk
<div {% if isDev %} class="debug" {% endif %} ></div>
<!-- or -->
<div class="{{ 'debug' if isDev }}"></div>

For 11ty by analogy . Only use addGlobal

A
Aetae, 2020-10-04
@Aetae

Cheap and angry: a pre-commit hook that looks for this class name with a simple grep and does not allow you to commit if it finds it.)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question