If you’re anything like me, you like being lazy shortcuts. The“Deploy to Netlify” buttonallows me to take this lovely feature of my personality and be productive with it.
Clicking the button above lets me (or you!) instantly clone myNext.js starter projectand automatically deploy it to Netlify. Wow! So easy! I’m so happy!
Now, as I was perusing the docs for the button the other night, as one does, I noticed that you canpre-fill environment variablesto the sites you deploy with the button. Which got me thinking… what kind of sites could I customize with that?
Idea: “Link in Bio” website
Ah, the famed “link in bio” you see all over social media when folks want you to see all of their relevant links in life. You can sign up for the various services that’ll make one of these sites for you, but what if you could make oneyourselfwithout having to sign up for yet another service?
But, we also are lazy and like shortcuts. Sounds like we can solve all of these problems with the “Deploy to Netlify” (DTN) button, and environment variables.
How would we build something like this?
In order to make our DTN button work, we need to make two projects that work together:
- A template project (This is the repo that will be cloned and customized based on the environment variables passed in.)
- A generator project (This is the project that will create the environment variables that should be passed to the button.)
I decided to be a little spicy with my examples, and so I made both projects with Vite, but the template project uses React and the generator project uses Vue.
I’ll do a high-level overview of how I built these two projects, and if you’d like to just see all the code, you can skip to the end of this post to see the final repositories!
The Template project
To start my template project, I’ll pull in Vite and React.
npm init @vitejs/app
After running this command, you can follow the prompts with whatever frameworks you’d like!
Now after doing the wholenpm installthing, you’ll want to add a.local.envfile and add in the environment variables you want to include. I want to have a name for the person who owns the site, their profile picture, and then all of their relevant links.
VITE_NAME=Cassidy Williams VITE_PROFILE_PIC=https://github.com/cassidoo.png VITE_GITHUB_LINK=https://github.com/cassidoo VITE_TWITTER_LINK=https://twitter.com/cassidoo
You can set this up however you’d like, because this is just test data we’ll build off of! As you build out your own application, you can pull in your environment variables at any time for parsing withimport.meta.env. Vite lets you access those variables from the client code withVITE_, so as you play around with variables, make sure you prepend that to your variables.
Ultimately, I made a rather large parsing function that I passed to my components to render into the template:
function getPageContent() { // Pull in all variables that start with VITE_ and turn it into an array let envVars = Object.entries(import.meta.env).filter((key) => key[0].startsWith('VITE_')) // Get the name and profile picture, since those are structured differently from the links const name = envVars.find((val) => val[0] === 'VITE_NAME')[1].replace(/_/g, ' ') const profilePic = envVars.find((val) => val[0] === 'VITE_PROFILE_PIC')[1] // ... // Pull all of the links, and properly format the names to be all lowercase and normalized let links = envVars.map((k) => { return [deEnvify(k[0]), k[1]] }) // This object is what is ultimately sent to React to be rendered return { name, profilePic, links } } function deEnvify(str) { return str.replace('VITE_', '').replace('_LINK', '').toLowerCase().split('_').join(' ') }
I can now pull in these variables into a React function that renders the components I need:
// ... return ( <div> <img alt="{vars.name}" src="%7Bvars.profilePic%7D"> <p>{vars.name}</p> {vars.links.map((l, index) => { return <link key="{`link${index}`}" name="{l[0]}" href="%7Bl%5B1%5D%7D"> })} </div> ) // ...
And voilà! With a little CSS, we have a “link in bio” site!
Now let’s turn this into something that doesn’t rely on hard-coded variables. Generator time!
The Generator project
I’m going to start a new Vite site, just like I did before, but I’ll be using Vue for this one, for funzies.
Now in this project, I need to generate the environment variables we talked about above. So we’ll need an input for the name, an input for the profile picture, and then a set of inputs for each link that a person might want to make.
In myApp.vuetemplate, I’ll have these separated out like so:
<template> <div> <p> <span>Your name:</span> <input type="text" v-model="name"> </p> <p> <span>Your profile picture:</span> <input type="text" v-model="propic"> </p> </div> <list v-model:list="list"></list> <generatebutton :name="name" :propic="propic" :list="list"></generatebutton> </template>
In thatListcomponent, we’ll have dual inputs that gather all of the links our users might want to add:
<template> <div> Add a link: <br> <input type="text" v-model="newItem.name"> <input type="text" v-model="newItem.url"> <button>+</button> <listitem v-for="(item, index) in list" :key="index" :item="item"></listitem> </div> </template>
So in this component, there’s the two inputs that are adding to an object callednewItem, and then theListItemcomponent lists out all of the links that have been created already, and each one can delete itself.
Now, we can take all of these values we’ve gotten from our users, and populate theGenerateButtoncomponent with them to make our DTN button work!
The template inGenerateButtonis just antag with the link. The power in this one comes from themethodsin the<script>.</script>
// ... methods: { convertLink(str) { // Convert each string passed in to use the VITE_WHATEVER_LINK syntax that our template expects return `VITE_${str.replace(/ /g, '_').toUpperCase()}_LINK` }, convertListOfLinks() { let linkString = '' // Pass each link given by the user to our helper function this.list.forEach((l) => { linkString += `${this.convertLink(l.name)}=${l.url}&` }) return linkString }, // This function pushes all of our strings together into one giant link that will be put into our button that will deploy everything! siteLink() { return ( // This is the base URL we need of our template repo, and the Netlify deploy trigger 'https://app.netlify.com/start/deploy?repository=https://github.com/cassidoo/link-in-bio-template#' + 'VITE_NAME=' + // Replacing spaces with underscores in the name so that the URL doesn't turn that into %20 this.name.replace(/ /g, '_') + '&' + 'VITE_PROFILE_PIC=' + this.propic + '&' + // Pulls all the links from our helper function above this.convertListOfLinks() ) }, },
Believe it or not, that’s it. You can add whatever styles you like or change up what variables are passed (like themes, toggles, etc.) to make this truly customizable!
Put it all together
Once these projects are deployed, they can work together in beautiful harmony!
- Here’s my template repositorythat gets populated with the environment variables, andan example site made with it!
- Here is my generator repository that generates the environment variables, and the site that’s built with it!
This is the kind of project that can really illustrate the power of customization when you have access to user-generated environment variables. It may be a small one, but when you think about generating, say, resume websites, e-commerce themes, “/uses” websites, marketing sites… the possibilities are endless for turning this into a really cool boilerplate method.
위 내용은 환경 변수를 사용하여 'NetLify에 배포'버튼을 해킹하여 사용자 정의 가능한 사이트 생성기를 만듭니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

CSS가있는 커스텀 커서는 훌륭하지만 JavaScript를 사용하여 다음 단계로 가져갈 수 있습니다. JavaScript를 사용하면 커서 상태를 전환하고 커서 내에 동적 텍스트를 배치하고 복잡한 애니메이션을 적용하며 필터를 적용 할 수 있습니다.

2025 년에 서로를 ricocheting하는 요소가있는 대화식 CSS 애니메이션은 CSS에서 Pong을 구현할 필요가 없지만 CSS의 유연성과 힘이 증가하는 것은 LEE의 의심을 강화합니다.

CSS 배경 필터 속성을 사용하여 사용자 인터페이스 스타일에 대한 팁과 요령. 여러 요소들 사이에 필터를 배경으로 배경으로 배경으로하는 방법을 배우고 다른 CSS 그래픽 효과와 통합하여 정교한 디자인을 만듭니다.

글쎄, SVG '의 내장 애니메이션 기능은 계획대로 이상 사용되지 않았다. 물론 CSS와 JavaScript는 부하를 운반 할 수있는 것 이상이지만 Smil이 이전과 같이 물에서 죽지 않았다는 것을 아는 것이 좋습니다.

예, 텍스트-랩을위한 점프 : Safari Technology Preview의 예쁜 착륙! 그러나 Chromium 브라우저에서 작동하는 방식과는 다른 점을 조심하십시오.

이 CSS- 트릭 업데이트는 Almanac, 최근 Podcast 출연, 새로운 CSS 카운터 가이드 및 귀중한 컨텐츠에 기여하는 몇 가지 새로운 저자의 추가 진전을 강조합니다.

대부분의 경우 사람들은 Tailwind ' S 단일 프로퍼 유틸리티 중 하나 (단일 CSS 선언을 변경)와 함께 Tailwind ' s @apply 기능을 보여줍니다. 이런 식으로 선보일 때 @apply는 전혀 약속하는 소리가 들리지 않습니다. 그래서 Obvio

바보처럼 배포하는 것은 배포하는 데 사용하는 도구와 복잡성에 대한 보상과 복잡성이 추가됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

드림위버 CS6
시각적 웹 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.
