国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Web Front-end JS Tutorial Leaving the pipeline visible to monitor blog deployment

Leaving the pipeline visible to monitor blog deployment

Jan 14, 2025 pm 02:29 PM

One of the things that bothers me about Computaria is not being able to follow the deployment on the blog itself. So, since this bothers me, why not fix it?

The pipeline

Currently there are 2 ways to know if the deploy is running:

  • open the repository on the jobs/pipelines page and see the latest one running
  • open in the repository and scroll to README.md

Both solutions don't seem great to me. I would like something lighter in Computing itself.

The idea

After a brief consultation with Kauê I decided to follow his tip: post on /about.

In the first experiment:

Deixando a pipeline visível para acompanhar deploy do blog

Nah, it got ugly. I already know that I don't want this to appear by default. But to bring the information it is enough. I just need to hide what is ugly, and make it available even if ugly if explicitly requested.

Proof of concept: crashes unless specified

Well, the first thing to do is know if we should take any action. To this end, the presence of the query param status with the value true was defined as an API.

To get the URL, I used window.location. Inside the Location object there is the search field, which serves precisely to maintain the query params used to access the specific URL.

For example, for http://localhost:4000/blog/about?q=1 the value of window.location.search is ?q=1. To make it easier to deal with the content within the query params, there is an object of type URLSearchParams. As far as I could understand from the documentation, to instantiate URLSearchParams, I need the query string but without the ? of the prefix. I can achieve this with window.location.search.substring(1).

Now, with this object in hand, I can simply consult the value of any query param I want:

const queryParams = new URLSearchParams(window.location.search.substring(1));

if (queryParams.get("status") === "true") {
    console.log("oba, vamos exibir o pipeline!")
} else {
    console.log("nops, n?o vamos exibir nada")
}

With this in hand, I need to take the action of displaying the pipeline badge. For the sake of ease, I decided to put it as an includeable HTML snippet: _includes/pipeline.html. So, I have free HTML to manipulate as I see fit.

In the beginning, it was simply a

invisible:

<div>



<p>Para importar, no /about só precisei colocar {%include pipeline.html%} no come?o do arquivo, o Jekyll se encarregou de montar tudo certo.</p>

<p>Ok, vamos por o script para detectar se deveria ou n?o exibir a tag:<br>
</p>

<pre class="brush:php;toolbar:false"><script>
    const queryParams = new URLSearchParams(window.location.search.substring(1));

    if (queryParams.get("status") === "true") {
        console.log("oba, vamos exibir o pipeline!")
    } else {
        console.log("nops, n?o vamos exibir nada")
    }
</script>
<div>



<p>So far, so good. Agora, vamos mudar a exibi??o para display: block caso seja para exibir o pipeline, ou sumir logo de uma vez com a <div>. Pelo console da web, bastaria fazer algo nesse esquema:<br>
</p>

<pre class="brush:php;toolbar:false">const pipeline = document.getElementById("pipeline")

if (...) {
    pipeline.style.display = "block"
} else {
    pipeline.remove()
}

Placing in the HTML fragment:

<script>
    const queryParams = new URLSearchParams(window.location.search.substring(1));
    const pipeline = document.getElementById("pipeline")

    if (queryParams.get("status") === "true") {
        pipeline.style.display = "block"
    } else {
        pipeline.remove()
    }
</script>
<div>



<p>E... falhou. Por quê? Porque no momento que a fun??o rodar ainda n?o tem definido quem é o elemento com id pipeline. Ent?o preciso mudar o ciclo de vida para rodar o script apenas quando a página for carregada. Basta colocar o <script defer>, certo? Bem, n?o. Porque defer n?o funciona bem com inline, apenas com arquivo de source explícito. Veja a documenta??o.

<p>Ou seja, precisei colocar o arquivo JavaScript explicitamente para o Computaria. Como a priori tudo que está solto na pasta do blog é colocado como asset disponível para o Jekyll publicar, criei o js/pipeline-loader.js:<br>
</p>

<pre class="brush:php;toolbar:false"><script src="{{ "/js/pipeline-loader.js" | prepend: site.baseurl }}" defer>
</script>
<div>



<p>E no script:<br>
</p>

<pre class="brush:php;toolbar:false">const queryParams = new URLSearchParams(window.location.search.substring(1));
const pipeline = document.getElementById("pipeline")

if (queryParams.get("status") === "true") {
    pipeline.style.display = "block"
} else {
    pipeline.remove()
}

Great, let's do something useful and post the image? To dynamically create an element, just use document.createElement. Then I put the badge URL:

const queryParams = new URLSearchParams(window.location.search.substring(1));
const pipeline = document.getElementById("pipeline")

if (queryParams.get("status") === "true") {
    pipeline.style.display = "block"

    const pipelineImg = document.createElement("img")
    pipelineImg.src = "{{site.repository.base}}/badges/master/pipeline.svg"

    pipeline.appendChild(pipelineImg)
} else {
    pipeline.remove()
}

But it showed a broken image... hmmm, what is the message displayed on the console?

GET http://localhost:4000/blog/about/{{site.repository.base}}/badges/master/pipeline.svg [HTTP/1.1 404 Not Found 4ms]

Strange, should he have gotten the cute rpository URL? Oh, I noticed. He didn't process Liquid at all. To deal with this I decided to follow the example in css/main.scss, an empty frontmatter.

const queryParams = new URLSearchParams(window.location.search.substring(1));

if (queryParams.get("status") === "true") {
    console.log("oba, vamos exibir o pipeline!")
} else {
    console.log("nops, n?o vamos exibir nada")
}

This gives an error message because frontmatter is not javascript, and the error is shown in the first const. Since this bothers me, the most direct way I thought of to deal with it was to create a "harmless error" earlier. I added a ; right after the frontmatter:

<div>



<p>Para importar, no /about só precisei colocar {%include pipeline.html%} no come?o do arquivo, o Jekyll se encarregou de montar tudo certo.</p>

<p>Ok, vamos por o script para detectar se deveria ou n?o exibir a tag:<br>
</p>

<pre class="brush:php;toolbar:false"><script>
    const queryParams = new URLSearchParams(window.location.search.substring(1));

    if (queryParams.get("status") === "true") {
        console.log("oba, vamos exibir o pipeline!")
    } else {
        console.log("nops, n?o vamos exibir nada")
    }
</script>
<div>



<p>So far, so good. Agora, vamos mudar a exibi??o para display: block caso seja para exibir o pipeline, ou sumir logo de uma vez com a <div>. Pelo console da web, bastaria fazer algo nesse esquema:<br>
</p>

<pre class="brush:php;toolbar:false">const pipeline = document.getElementById("pipeline")

if (...) {
    pipeline.style.display = "block"
} else {
    pipeline.remove()
}

Annoyances...

As I continued testing, I noticed that a 308 constantly appeared in the network tab. But why did it appear? Well, because when expanding Liquid, it ended up with a double bar before badges.

I originally got this:

  • https://gitlab.com/computaria/blog//badges/master/pipeline.svg

With redirection to:

  • https://gitlab.com/computaria/blog/badges/master/pipeline.svg

And this started to bother me as I analyzed whether I was using cache or not. To solve this I should get rid of the double slash. I could just get rid of it by not putting the slash right after the Liquid value being expanded, because after all I could know a priori that the {{site.repository.base}} string ended with /. But, just in case, it doesn't realistically hurt to put that slash before /badges/master/pipeline.svg, it's even an indicator for myself as a reader.

But, since I don't want to rely on prior knowledge of whether or not this bar exists, I had two options for this:

  • treat the Liquid expansion level to remove the terminal slash
  • handle the creation of this string at a javascript level

The JavaScript side seemed easier to me. So just replace // with /, correct? Hmmm, no. Because the protocol appears before ://, so just making this crude substitution would result in the url starting like this: https:/computaria.gitlab.io. To get around this, I make the following substitution:

<script>
    const queryParams = new URLSearchParams(window.location.search.substring(1));
    const pipeline = document.getElementById("pipeline")

    if (queryParams.get("status") === "true") {
        pipeline.style.display = "block"
    } else {
        pipeline.remove()
    }
</script>
<div>



<p>E... falhou. Por quê? Porque no momento que a fun??o rodar ainda n?o tem definido quem é o elemento com id pipeline. Ent?o preciso mudar o ciclo de vida para rodar o script apenas quando a página for carregada. Basta colocar o <script defer>, certo? Bem, n?o. Porque defer n?o funciona bem com inline, apenas com arquivo de source explícito. Veja a documenta??o.

<p>Ou seja, precisei colocar o arquivo JavaScript explicitamente para o Computaria. Como a priori tudo que está solto na pasta do blog é colocado como asset disponível para o Jekyll publicar, criei o js/pipeline-loader.js:<br>
</p>

<pre class="brush:php;toolbar:false"><script src="{{ "/js/pipeline-loader.js" | prepend: site.baseurl }}" defer>
</script>
<div>



<p>E no script:<br>
</p>

<pre class="brush:php;toolbar:false">const queryParams = new URLSearchParams(window.location.search.substring(1));
const pipeline = document.getElementById("pipeline")

if (queryParams.get("status") === "true") {
    pipeline.style.display = "block"
} else {
    pipeline.remove()
}

Breaking it down:

  • in place of the replacement, put what was found in the "first group" followed by a slash
  • regex matches: anything other than : (in a group), slash, slash

With this change, https:// does not have match with ([^:])//, but all other occurrences of // in the path have a perfect match, as they will not be in front of one :. To be more strict, I could work to prevent the match from occurring in query param/fragment, but it seemed too overkill.

Proof of Concept: Cacheless Loading

Ok, having defined the details of where to place it and the locking mechanism, we need a reloading mechanism. First attempt: simply create a new image element. But still, how? The ideal would be "after some time". So this gives me two options, well to say:

  • setTimeout
  • setInterval

Okay, let's go with what does this do? setTimeout receives a command that will be executed after a time interval AND also the given interval. It gives you back an ID that you can remove using clearTimeout. To repeat the call, setTimeout needs to be called again at the end.

setInterval is almost the same thing, only it will always execute the command after the time interval. The return should be an ID that you would call clearInterval to remove, but according to the documentation it works with clearTimeout too (just in case, don't trust it, use the one with correct semantics).

Using setTimeout

Shall we create a loop call with setTimeout? How about printing the word pumpkin 5 times in a text field? I'll put a textarea for this experiment:

const queryParams = new URLSearchParams(window.location.search.substring(1));

if (queryParams.get("status") === "true") {
    console.log("oba, vamos exibir o pipeline!")
} else {
    console.log("nops, n?o vamos exibir nada")
}

Ok, I have 3 functions that I would like to be reachable by HTML. And they divide (even if very slightly) a state. I'm a sucker for hiding things, so I don't want this state to be visible outside the

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Java vs. JavaScript: Clearing Up the Confusion Java vs. JavaScript: Clearing Up the Confusion Jun 20, 2025 am 12:27 AM

Java and JavaScript are different programming languages, each suitable for different application scenarios. Java is used for large enterprise and mobile application development, while JavaScript is mainly used for web page development.

Javascript Comments: short explanation Javascript Comments: short explanation Jun 19, 2025 am 12:40 AM

JavaScriptcommentsareessentialformaintaining,reading,andguidingcodeexecution.1)Single-linecommentsareusedforquickexplanations.2)Multi-linecommentsexplaincomplexlogicorprovidedetaileddocumentation.3)Inlinecommentsclarifyspecificpartsofcode.Bestpractic

How to work with dates and times in js? How to work with dates and times in js? Jul 01, 2025 am 01:27 AM

The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

Why should you place  tags at the bottom of the ? Why should you place tags at the bottom of the ? Jul 02, 2025 am 01:22 AM

PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

JavaScript vs. Java: A Comprehensive Comparison for Developers JavaScript vs. Java: A Comprehensive Comparison for Developers Jun 20, 2025 am 12:21 AM

JavaScriptispreferredforwebdevelopment,whileJavaisbetterforlarge-scalebackendsystemsandAndroidapps.1)JavaScriptexcelsincreatinginteractivewebexperienceswithitsdynamicnatureandDOMmanipulation.2)Javaoffersstrongtypingandobject-orientedfeatures,idealfor

JavaScript: Exploring Data Types for Efficient Coding JavaScript: Exploring Data Types for Efficient Coding Jun 20, 2025 am 12:46 AM

JavaScripthassevenfundamentaldatatypes:number,string,boolean,undefined,null,object,andsymbol.1)Numbersuseadouble-precisionformat,usefulforwidevaluerangesbutbecautiouswithfloating-pointarithmetic.2)Stringsareimmutable,useefficientconcatenationmethodsf

What is event bubbling and capturing in the DOM? What is event bubbling and capturing in the DOM? Jul 02, 2025 am 01:19 AM

Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

What's the Difference Between Java and JavaScript? What's the Difference Between Java and JavaScript? Jun 17, 2025 am 09:17 AM

Java and JavaScript are different programming languages. 1.Java is a statically typed and compiled language, suitable for enterprise applications and large systems. 2. JavaScript is a dynamic type and interpreted language, mainly used for web interaction and front-end development.

See all articles