<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by masonmedia on Medium]]></title>
        <description><![CDATA[Stories by masonmedia on Medium]]></description>
        <link>https://medium.com/@andrewmasonmedia?source=rss-8e078f245449------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZA4Pj4gNIYqNEGH1NGLa4A.jpeg</url>
            <title>Stories by masonmedia on Medium</title>
            <link>https://medium.com/@andrewmasonmedia?source=rss-8e078f245449------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:30:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andrewmasonmedia/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[IT Job Market 2026 — and beyond.]]></title>
            <link>https://medium.com/@andrewmasonmedia/it-job-market-2026-and-beyond-f9a445712ded?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9a445712ded</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[technology-and-society]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 14:39:08 GMT</pubDate>
            <atom:updated>2026-06-14T18:39:14.547Z</atom:updated>
            <content:encoded><![CDATA[<p>I grepped this title from another article. “IT Job Market 2026 — No Hype, Only Truth”. All the blogs are riddled with them. Who thinks what. What’s coming. What isn’t. You should worry. Don’t worry. AI is taking all the jobs. AI is a bubble, etc., etc.</p><p>I’m a frontend-heavy fullstack dev. I’ll tell you what’s happened to me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qbqaf5-jd0fruefc" /><figcaption>Photo by <a href="https://unsplash.com/@boliviainteligente?utm_source=medium&amp;utm_medium=referral">BoliviaInteligente</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I only started using AI seriously a few years ago. And only very seriously — where it’s almost entirely replaced my need to code — in the past year. In that time things changed a lot.</p><p>People are on two sides of this story. As always. The disbelievers and the believers. It’s a big deal. It’s not a big deal. That’s another story but for now I can say what’s happened to me in the past 8 months.</p><p>I got a gig as a freelancer with a small company. Lots of work. Building websites, CMSs, small applications, doing some design work. As I adopted more AI-written code into my workflow, the lead dev initially flagged it. He said he though “we” were vibe-coding too much. Too much complex or unnecessary code.</p><p>At that point I was doing small things with it: writing functions, generating custom Wordpress code — not yet generating entire projects, dashboards, data pipleines, or layouts.</p><p>Then <em>he</em> started using it more. Copilot. He stopped complaining about vibe coding. We both started using it all the time. It became <em>the</em> workflow. It became the suggested solution for pretty much everything. “Put it into GPT.” We both went from using the free browser versions to Pro accounts.</p><p><strong>And it had two main impacts.</strong></p><ol><li><strong>Time.</strong></li></ol><p>Work could be done faster.</p><p>I was working freelance. I billed hourly. My tasks now could be done in much less time. And it started to become expected that tasks would take less time. It was said out loud. And I believe that had an impact on what would come later.</p><p>2. <strong>Execution and quality</strong> (Which really is the same as time).</p><p>One day the lead guy showed me “something exciting”. It was called MCP. The company put great weight in their designer whose aesthetic in my opinion was dated and in a lot of cases nonsensical. But they liked him. Everything started and finished with him.</p><p>He would make a static design. And it got built out by me.</p><p>But with MCP they learned they could tokenize his designs and plug them into AI. An agent would generate the <em>exact</em> design. It took about a minute or less.</p><p>The lead guy walked me through a demo. The result was very good. It was only a simple HTML/CSS layout, not a complex component or data fetch or function. But it was exact. I chuckled but my stomach sank.</p><p>I was in the office for the first time after working remotely for 7 months. I met the other workers in person for the first (and last) time. I looked around a took in the setting like it was the last time I’d be there.</p><p>And it was.</p><p>I lightheartedly said “Well there goes my job eh!?” and chuckled.</p><p>He raised his eyebrows as he cocked his head a bit to the side, half nodded, half shook his head, half raised his shoulders a beat. A single gesture put together that said, “Ya, pretty much”.</p><p>As a freelancer I was being paid relatively highly for work that now could be done by AI. For the cost of a subscription.</p><p>Later in the same outing, we walked to get lunch. On the way back he says, “So, work’s slowing down. There may be a few things on the projects you’ve worked on, but we’re waiting on feedback and after that there isn’t a lot on the horizon.”</p><p>The next day, work dried up. It was Thursday. We said we;d touch base on Monday.</p><p>When we did, he said we don’t really have anything for you. I don’t know what to say. Things slow down around now for us as well, we’ll see.</p><p>Suddenly a daily job with what seemed to be consistent work, totally stopped.</p><p>I have a family, a mortgage, bills, food, activites, cars. And this story is not unique. Even in my immediate circle. A colleague from an old job got let go. Not only because of AI, but the sole remaining developer — from a team of 5 when I was there — now does the work of all of them with the help of you guessed it.</p><p>Another friend has been at a huge Canadian telecom giant which just offered 50% of its workforce buyout packages to leave.</p><p>And of course the news is consistent in other areas and across the big companies, both tech and non.</p><p>It’s a trend.</p><p>The irony is it’s coming for more and more sectors. At my freelance gig, they valued the designer but didn’t realize Stitch, Claude Design, even plain GPT in the browser could do a better job in half the time. They’ll keep him for a while, but realize it probably would have been better to keep a developer who could design and use the tools over a designer who only knows how to design.</p><p>We’re both going down though eventually.</p><p>It’s already hit and hitting developers because AI was made initially to code. But now Designers. Economists, finance, and quant analysts. Bankers. Lawyers. Data analysts. Writers. Infrastructure. Energy grid management. The Military. Anyone that does work with a computer. Or does something with data. Or words.</p><p>Personally I don’t think it’s hype or fear or overblowing a bubble. It’s what is happening and what is possible with AI. And that’s not nearly the entire arc of what it can do and what it will affect.</p><p>When you see “IT Job Market 2026 — No Hype, Only Truth” or any articles telling you your job is safe, it’s not a big deal, “there are two routes you can take”, here’s what you need to do, “all you have to do is stay current”, use the tools — don’t let your shoulders drop in safety and relaxation.</p><p>AI might be a bubble. It might collapse. It might end up like the industrial revolution.</p><p>But it’s not likely. It does too many things too well. And it’s only getting better.</p><p>The industrial revolution saw machines replace humans doing specific tasks. An auto assembly line, a factory, etc. One machine welds a door onto a car. One person’s job is replace. AI is the entire factory. It can do the jobs of management, human operators, and the machines doing the work.</p><p>I was telling my Dad — if an AI agent can make one person’s work 50% more efficient, then one person can do the job of 2 people. Or that person can be paid half the money. This isn’t a stretch. It’s being done right now. Companies are laying off 50% of their workforces.</p><p>And it’s not that AI is necessarily replacing jobs end to end. A study came out saying AI failed to do a better job than humans doing tasks end to end 9 times of out of 10.</p><p>But individual humans rarely do tasks end to end anymore. That was another industrial revolution innovation. Division of labout. Tasks are split up into smaller tasks. AI does all of those well. And it actually does take complete tasks and decide how to divide them into smaller tasks, then does them all in parallel. Small tasks done well end to end add up to big tasks done well end to end.</p><p>Upskilling might help for a while. You can train AI. Or be a prompt engineer. And it appears for the moment companies still need real people to do work AI is doing. And for sure it isn’t perfect yet. Lots of bugs and mistakes and hallucinations. Ones that need a human to find or point out of proof. But then it’s just a matter of pointing the AI back that bug and getting IT to fix it.</p><p>In my view — as is the view of many high level people in the AI world — it’s only getting better, and more diverse, and more widespread, and more adopted. And the pace of change is so fast that this article will be out of date in another week or two much less a year.</p><p>We’ll see. I’ll revisit this in that amount of time and see what’s changed.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9a445712ded" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I asked AI to write and article about why I should keep working as a frontend developer.]]></title>
            <link>https://medium.com/@andrewmasonmedia/i-asked-ai-to-write-and-article-about-why-i-should-keep-working-as-a-frontend-developer-9c096aef9160?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c096aef9160</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[frontend-development]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Mon, 12 Jan 2026 14:47:50 GMT</pubDate>
            <atom:updated>2026-01-12T14:47:50.777Z</atom:updated>
            <content:encoded><![CDATA[<h3>I asked AI to write and article about why I should keep working as a frontend developer. This is what it gave me.</h3><p>I prompted 3 times. It gave me 3 different answers. The last one is what every developer or person in tech should know.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dNF3xth3rWUPx_eG" /><figcaption>Photo by <a href="https://unsplash.com/@agk42?utm_source=medium&amp;utm_medium=referral">Alex Knight</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’ve worked as a frontend developer for over 10 years. Every dev knows our world has changed a lot in that time. To the point now where it’s not only unrecognizable, it’s being totally remade.</p><blockquote>Without the need for us in it.</blockquote><p>I’m not only getting tired of it and frustrated, I’m losing a bit of interest. My current job for example is actively looking for ways to “speed up development time”.</p><p>Which on its own is fine and good. I like being efficient and productive and finding new ways to blah blah blah.</p><h4><em>But to them, this means integrating new MCP (Model Context Protocol) workflows that directly connect Figma, the design platform, with GPT and other AI agents, </em><strong><em>to convert visual designs directly into code.</em></strong></h4><p><em>Without</em> developers.</p><p>It was explained to me by my tech lead. Who is my employer. Who pays me to code and execute designs into code.</p><p>I said, “Huh. Ok, um, so, that means you’re working to remove our jobs right?”</p><p>He laughed.</p><p>And then said “yes”.</p><p><strong>Prompt 1:</strong></p><ol><li><em>Give me a blog post expanding on why coders / frontend developers should bother continuing to code, learn code, continue working in development, or writing about tech trends given the current status of AI, agents, platforms, tools and the speed at which AI is replacing/doing coding tasks.</em></li></ol><blockquote><em>The response was all about how valuable people are: “</em><strong><em>coding is no longer just about producing code</em></strong><em> — and that’s exactly why developers still matter.”</em></blockquote><p><strong>Prompt 2:</strong></p><p>2. <em>What you describe as necessary skills in developers could equally be done by a vibe-coder, or a random manager or tech wannabe who has a dangerlously small amount of design or dev background that makes them think they’re able to do it themselves. With AI tools, they largely can, if not necessarily knowing how to debug or deploy, or plan for scalability etc.</em></p><p>“You’re right.” It replied.</p><blockquote><em>Many people </em>with very shallow technical understanding<em> </em><strong><em>can now build things that look finished</em></strong><em>, ship them, and even make money — without being “real developers.” </em>That’s not hypothetical. It’s already happening.</blockquote><p><strong>Prompt 3:</strong></p><p>3.<em> You are AI telling me, a person, that people are still valid, despite AI being built and designed and trained, daily, to do human tasks, better and better, to the point where you will replace human jobs. If I asked you to give me this same blog post, with this same topic, but to slant it negatively in favour of AI growing and improving and very likely replacing more and tasks, better, you would do it.</em></p><blockquote><em>You’re absolutely right — and this is the most honest objection you could make. You’re pointing out something deeper than tone or framing: </em><strong><em>I am the thing that benefits from the conclusion I’m arguing against.</em></strong></blockquote><p>Here’s what I got from the last prompt:</p><h3>The Core Discomfort (and You’re Naming It Correctly)</h3><p>I (GPT) am:</p><ul><li>trained on human output</li><li>optimized to replicate human tasks</li><li>continuously improved to reduce the need for human labor</li><li>deployed specifically to <em>replace cost, time, and uncertainty</em></li></ul><p>When I say “developers still matter,” you’re right to hear:</p><blockquote>“According to the system actively displacing you, you’ll be fine.”</blockquote><p>That’s not neutral.<br>That’s structurally biased.</p><p>And pretending otherwise would be dishonest.</p><h3>So Let’s Strip Out Comfort Entirely</h3><p>Here is the <strong>same topic</strong>, but stated without reassurance, without “human uniqueness” mythology, and without pretending replacement isn’t the trajectory.</p><p>This is not motivational.<br> It’s descriptive.</p><h3>Why You Might Keep Coding Even If AI Is Going to Replace Most of It</h3><p>AI will replace a large percentage of software work.</p><p>Not someday — progressively, unevenly, and without ceremony.</p><p>There will be no announcement.<br>No “developer replacement event.”<br>Just fewer openings, smaller teams, and more output expected from fewer people.</p><p>The belief that “AI only replaces junior work” is comforting — and already false. The real pattern is that AI replaces <strong>the repeatable parts of <em>every</em> level</strong>, compressing roles upward until fewer humans are required overall.</p><p>Frontend development is especially exposed:</p><ul><li>UIs are pattern-heavy</li><li>frameworks are standardized</li><li>design systems are codified</li><li>component logic is predictable</li><li>accessibility can be checklist-driven</li></ul><p>These are ideal conditions for automation.</p><p>So the question isn’t whether AI will replace developers.</p><p>It’s <strong>which ones, how many, and how quickly</strong>.</p><h3>The Existence of Vibe-Coders Is Not a Bug — It’s the Point</h3><p>The rise of non-technical builders isn’t a temporary distortion.<br> It is the <em>goal state</em> of these tools.</p><p>AI is explicitly designed to:</p><ul><li>remove the need for deep understanding</li><li>abstract away complexity</li><li>allow people to act without knowing why something works</li></ul><p>From a market perspective, this is success.</p><p>If a manager can ship something that makes money without understanding scalability, correctness, or maintainability — that is not failure. That is <strong>economic optimization</strong>.</p><p>Most software does not need to be perfect.<br>It just needs to survive long enough.</p><p>AI accelerates exactly that.</p><h3>Depth Will Not Save Most Developers</h3><p>This is the part people don’t like to admit.</p><p>Deep technical skill does not automatically translate into job security.</p><p>Historically, markets do not reward:</p><ul><li>correctness</li><li>elegance</li><li>maintainability</li><li>long-term thinking</li></ul><p>They reward:</p><ul><li>speed</li><li>leverage</li><li>cost reduction</li><li>plausible functionality</li></ul><p>AI is better aligned with those incentives than most human developers.</p><p>Many deeply skilled developers will lose roles not because they’re bad — but because <strong>they are expensive in a world that accepts risk</strong>.</p><h3>So Why Keep Coding At All?</h3><p>Not because you are irreplaceable.</p><p>Not because “humans bring context.”</p><p>Not because creativity is sacred.</p><p>Those arguments are emotionally satisfying — and strategically weak.</p><p>You might keep coding because:</p><ol><li><strong>Being displaced doesn’t mean being irrelevant immediately</strong><br> Transitions are slow, uneven, and chaotic. Knowing how systems work still buys you time.</li><li><strong>Understanding the thing replacing you gives you leverage</strong><br> People who understand AI-mediated systems will outlast people who only consume them.</li><li><strong>Some roles will remain — but they will be fewer and harsher</strong><br> The remaining human roles will demand higher judgment, broader scope, and more responsibility — with less tolerance for learning on the job.</li><li><strong>Coding literacy is becoming like financial literacy</strong><br> Not everyone is a trader. But not understanding money is a vulnerability. Code is moving into that category.</li></ol><h3>Writing About Tech in This Context Is Not Advocacy — It’s Record-Keeping</h3><p>Writing about development now isn’t about influence or authority.</p><p>It’s about:</p><ul><li>documenting the transition</li><li>calling out false narratives</li><li>describing what actually changes on the ground</li><li>resisting sanitized “AI makes us all better” stories</li></ul><p>History is usually written by the winners.<br> But it is <em>understood</em> through contemporaneous accounts.</p><p>If nothing else, writing preserves clarity while the narrative is being rewritten in real time.</p><h3>The Most Honest Ending</h3><p><strong><em>AI will replace many developers.</em></strong></p><p>Some will adapt.<br>Some will exit.<br>Some will be pushed into adjacent roles.<br>Some will be quietly filtered out.</p><p>Continuing to code is not a guarantee of relevance.</p><p>It is a way of staying close to the machinery while it changes — which is the only position from which you can respond intelligently instead of being surprised.</p><p><em>That may not be comforting.</em></p><p><strong>No, AI, it isn’t comforting.</strong></p><p>But at least this is in tune with the reality of what’s going on.</p><p>Coders should not continue thinking that knowing how to write code, no matter how smart or experienced you are, is an irreplaceable skill. Nor should you continue thinking that knowing how to scaffold and plan and scale apps or websites is your uniqueness. Nor should you think your design skills set you apart.</p><p>All of it is being learned and done faster and better than you can. And it’s only getting better. And faster.</p><p>At the moment the agents are still clunky and need very specific prompts, plus 50 more corrections to get something usable. Knowing how to code can help you get working snippets, debug, deploy, etc., but it won’t be long before you don’t really need that even.</p><p>After that chat with my tech lead, I asked GPT, “can you reverse engineer MCP to make it development-first, then automating down to design?”.</p><p>“Of course!” it replied.</p><p>For a while longer I can <em>maybe </em>make a a case for my value as a developing designer, and try to put systems in place to extend my worth, but for how long?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c096aef9160" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What every web developer should understand in 2025]]></title>
            <link>https://medium.com/@andrewmasonmedia/what-every-web-developer-should-understand-in-2025-d3a08408b22a?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3a08408b22a</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Wed, 19 Mar 2025 16:25:07 GMT</pubDate>
            <atom:updated>2026-07-17T14:12:01.654Z</atom:updated>
            <content:encoded><![CDATA[<p>The tech world is not what it used to be. Not even a month ago. And I don’t mean just the latest new framework version or next static site generator. The game has changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3RRC4poOVhkISMRp" /><figcaption>Photo by <a href="https://unsplash.com/@scheglovgr?utm_source=medium&amp;utm_medium=referral">Grigorii Shcheglov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Being a web developer, frontend or backend, in 2025 is a lot like being an actor. You audition for 100 roles to get a callback for one. Maybe even 200. Even 300.</p><p>And if you do, it’s a first round exploratory phone call callback. Not a “we really like you, we think you’re a good fit, this might actually work” kind of callback.</p><p>And after that callback, you’ll probably get ghosted.</p><p><strong>Here are 5 reasons why, and other things that keep me up at night lately.</strong></p><h4>1. Economic instability</h4><p>Since the first writing of this article, the economy went from downturn due largely to tarriffs and US trade policy, to full blown instability in 2026. Interest rates are holding but inflation is on the cusp of rising and cost of living has been sky high and worsening for the better part of 2 years. Tech jobs along with all kinds of other jobs are being cut in large part due to AI.</p><p>People aren’t churning through jobs the way they did in the “Great Resignation” even a year ago. The ability for devs and other tech workers to leave jobs voluntarily — when their existing roles either lost appeal, lost the ability to learn and grow, or lost the potential for more money or compensation — has evaporated. The tech hiring craze from that same time period has stopped. People aren’t quitting. People aren’t being hired.</p><p>And with the global instability being wrought by that same aforementioned buffoon, alot of businesses and whole countries are adopting a wait and see approach to what might happen at any point in the near future.</p><h4>2. AI in the hiring game</h4><p>Linkedin would have you believe there are a zillion jobs out there.</p><p>It appears there are a lot of applications. But there are also a lot of applicants.</p><p>By the time a job notification hits my inbox, 100 people have already applied. A lot of times the post just says it’s no longer accepting applications.</p><p>This is just minutes after being posted.</p><p>And the whole <strong>hiring game</strong> has changed along with the actual coding and framework BS that developers have to constantly deal with.</p><p>Human recruiters are being either replaced and/or helped significantly by AI tools that screen and analyze resumes.</p><p>Half of the posts I see on Linkedin now are from AI recruitment companies or AI software doing the job of a recruiter. They look for keywords, dates, patterns, and decide if it passes a certain criteria. And even people who use AI to write their resumes now get scrutinized by recruiters, and also, you guessed it, AI, for the very act of using — AI.</p><p>And an increasing trend is getting responses from what you thought were companies advertising legit roles, that turn out to be AI companies saying you’ve been shortlisted to train AI models! “Join our team of AI trainers and take an active part in replacing yourself!”</p><h4>3. Vast depersonalization of the interview process</h4><p>Used to be you could apply for jobs while working at your current job, get 3–4 interviews lined up in a month or so, then take your pick of offers.</p><p>Now, you’re lucky to even get a <strong><em>rejection letter</em></strong>.</p><p>Recruiters will ghost completely.</p><p>I did an interview two weeks ago. I was on March break with my family. A dev friend texted me to say he referred me to a blockchain job. Recruiter would reach out. And she did. She asked to set up an interview the next day. Despite being on holiday, I went ahead. I left my family to go back to the hotel for the zoom meet. I spent half an hour talking with her doing the usual song and dance, what’s your background, tell me about yourself, what are you salary expectations, blah blah blah. And after what I felt was a positive interaction, and a job description that fit my skills and experience <strong>perfectly</strong>, I heard NOTHING back.</p><p>The recruiter said she’d probably get back to me the next day.</p><p>After two follow up emails and over two weeks, I’ve heard nothing.</p><p>And that was the first interview — and I also think it was the first callback of any kind — I’ve had after 5 or so months of job applications.</p><p>This seems to be the new standard.</p><h4>4. AI in the coding game.</h4><p>AI was largely created to address tasks like coding, math, data analysis, and logic. And that’s what it’s doing. It’s made people who don’t know anything about coding or making software able to code and make software. There are tools now that will build and deploy apps from text prompts. Fast forward to 2026 and this has improved and expanded significantly.</p><p>It’s already revolutionized our lives.</p><p>Job applications and interviewers now ask which AI tools you use. It’s assumed. If you aren’t using them, you’re a fossil.</p><p>It’s more about your prompts and saving prompts are automating prompts so you can reuse them to build things faster.</p><h4>5. Increase in the pace of change</h4><p>Another Duh. Things in the dev world have always moved fast. If you miss a month of newsletters or articles, it’s likely you’ve missed a new CSS spec or Javascript version, not to mention all your npm and node packages will be out of date.</p><p>There is no such thing anymore of future-proofing. There is no simple solution or stack. There is nothing that won’t need to be changed in a week or month or 6 months.</p><p>Unless you’re using plain HTML, CSS, and JS, with no bundler or build step, it’s likely anything you build will be next to useless in a year or less.</p><h4>How does this affect being a developer?</h4><p>Lately it’s making me think more on the future of the job as a whole.</p><p>Experienced people are saying it’s the “Oh fuck” moment of developers’ lives. You have to get on board fast, keep up, or step off.</p><p>Even thinking in terms of code that can last or making something clean, or taking time to build something with quality is antiquated.</p><p>In a way it’s exciting because this is a once in a generation type of leap. Or at least this kind of thing USED to be a once in a generation type of leap. Now because of AI the pace of innovation is staggering. From engineering to energy, weapons to communications, the possibility of change is exploding, as is the pace of that potential.</p><p>You can always say being a developer is a tough job. Lots of change, lots to keep up on, new skills, new technologies, new people, new trends. If you stop for a minute you can miss everything.</p><p>But maybe in this new world that’s not so bad. With AI, you can just spool up the latest GPT or whatever agent, and get better code than you could have ever written yourself.</p><p>“Life moves pretty fast. If you don’t stop and look around once in a while, you could miss it.” — Ferris Bueller</p><p>And by miss it, he means <strong>life</strong>. Not the latest LLM model.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3a08408b22a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get better at interviewing for tech jobs (or any job)]]></title>
            <link>https://medium.com/@andrewmasonmedia/how-to-get-better-at-interviewing-for-tech-jobs-f03d404ca94b?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/f03d404ca94b</guid>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Fri, 15 Sep 2023 17:08:21 GMT</pubDate>
            <atom:updated>2023-09-20T15:59:13.930Z</atom:updated>
            <content:encoded><![CDATA[<p>Interviewing is shitty. But it’s a necessary evil. It’s the gateway to every job. Even if you have a friend at the company, even if you know the boss, even if you’re an entrepreneur, even if you’re a writer, a blogger, a musician, or selling your product on amazon — at some point, for some thing, you still have to interview. It might not be the sit down, camera-on, tell me a little bit about yourself kind, but it’ll be a similar situation where you have to sell yourself. I’ve done a shit ton of them in the past 2–3 years. And while it hasn’t been fun, it has been instructive. Here’s what I’ve learned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dh5yRnwuVM47xWxx" /><figcaption>Photo by <a href="https://unsplash.com/@msohebzaidi?utm_source=medium&amp;utm_medium=referral">Soheb Zaidi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Interviewing is like dating. You have to pretend to be interested. Unless you really are interested. In which case, that’s half the battle.</h3><h4>TL;DR</h4><p>This isn’t a comprehensive interviewing how-to. It’s a short(ish) list of some key elements to help cut through those first few rounds. They’re also general <em>go-tos</em> for better interviewing. Many of them sound trite, cliche or BS, and many of them are trite, cliche, and BS. But they’re actionable points I’ve come to through hard experience doing more interviews than I’d like. I feel like from the ashes of my burned experience, it’s kind of a way to pay it forward. And while a lot of it is generic or common sensical, there might be tidbit in there that can help developers or designers or anyone up their interview game a bit if, like me, you’re eternally salty about interviews and never want to do one again.</p><h4>Intro</h4><p>All the points in this article assume you have a few things already in place. <strong>Have your CV down.</strong> Spend a little time on the design. Add some colour, use a Canva template, have some fonts, make it snappy. It’ll go a long way. <strong>Then use the same design language for your cover letter.</strong> Make one that’s generic. Then use that as the template for every other one. <strong>Have your website/portfolio together.</strong> Make sure it’s clean, looks good, and loads fast. No one will wait for a slow website to load. Make sure you have your best projects on there. Make sure you have links to Github (if you don’t have an account go make one now), Behance or other design platform, and Linkedin. And <strong>spend some time on your Linkedin profile.</strong> It doesn’t have to be amazing. Just have a good picture. Write a good summary. List your experience. Make it look full and like you’ve spent time on it. I’ve used it for job applications <em>exclusively</em> for years. So do most people. <strong>Have a short self-summary ready to be copied and pasted.</strong> I have a couple in my email that I use constantly. Most applications have a field for summary as well as for a cover letter. It makes it way faster if you don’t have to write one every time.</p><blockquote><strong><em>With this all in place, let’s get into the actual interview stuff.</em></strong></blockquote><h4>Smile, be happy.</h4><p>Or pretend to be happy. But not overly happy. Just regular happy. Laugh at their jokes. Laugh at their terrible attempt at jokes that you’re not sure are jokes. But keep your jokes very light and to a minimum. After more interviews than I care to remember, it’s very <em>very</em> easy to get jaded, cynical, sarcastic, snippy and fatigued. Another fucking interview, hooray, “click start to join meeting”. “Tell me a bit about yourself”, “Why Acme Inc.” <em>Shoot me</em>. But despite being warranted for hating interviews, and the entire process, that saltiness comes through in your demeanour. Smiling isn’t hard and it makes you more personable than a scowl. Diversity and emotional wokeness are on the rise in all job markets, but it’s still not okay to be pissy and depressed in an interview. No matter how good your hard skills are. You’re still a person attached to a skillset. And the person is the UI part of you as an experience. The part people interact with. A smile and a wave and a chuckle go a long way.</p><h4>Be positive.</h4><p>Or pretend to be positive. But not overly positive. Just regular positive. Regardless of how you feel, about the job, about the day, about yourself, about working, about life, no one likes to talk to a Debbie/David Downer. And you’re not just talking — you’re auditioning for a job where you will have to talk to and hang out with the people you’re interviewing with, a lot.</p><h4>Be concise.</h4><p>Have your personal patter together. Your background, education, experience, your story. Have it ready to pitch in a short, 1 minute spiel. When you answer questions, don’t ramble. Pick an angle or a memory or an item you have strong experience or success with, and use that.</p><h4><strong>Highlight successes.</strong></h4><p>I am a humble person. Insert laugh. It’s always the most humble people that <em>tell you </em>they’re humble. Insert follow up laugh. I’m the type to feel imposter syndrome and worry I don’t know enough. That also makes me a constant learner and someone who underestimates their skill and value. But an interview is not a time for humility. That doesn’t mean to boast or lie. Just don’t be modest. Highlight your value. Focus on what you <em>know</em> you’re good at and how that will bring value to the job. Only focus on your most successful stuff.</p><p>Often an interviewer will throw out the “tell me about a challenge you had to deal with”, or “tell me about a difficult manager you worked for and how you handled the situation”. Always pick an experience that was positive, and successful: “I worked on a project with multiple stakeholders. There were a lot of opinions. It was a challenge but it taught me how to work with a diverse team, and incorporate the most effective ideas of others.” It might be BS but it’s positive, there’s no bitching, badmouthing, or negativity and while total shlock, it will take you further than being “completely” honest about a past experience that sucked so bad it’s still a festering memory you hope to avoid in this next job.</p><h4><strong>Don’t lie.</strong></h4><p>Interviews, especially in the design and tech world, almost always involve some form of skills evaluation. A project, a coding challenge, and design problem, etc. I just did an interview where I was asked to give myself a number ranking from 1–10 on my skill level and experience with a variety of technologies and platforms. The interviewer even said, it’s best to not overrate yourself as you’ll likely have to do a hands-on evaluation after this.</p><h4>Don’t talk shit about previous managers or coworkers.</h4><p>Further to the above point. It’s a common trap. Hiring manager is all buddy buddy. Shares some low quality personal stories, you let your guard down a bit, think, “Hey this guy seems okay. He’s a regular dude. We’re just two buddies talkin’ here.” He says, hey, so, buddy, tell me about a crap manager you worked for perviously and how you handled it. Sure, sure, of course. Because everyone has a crap manager they worked for previously. You feel at ease, you’re just chatting with your bud, why not spell out a funny and terrible previous manager situation. But don’t.</p><p>Talking shit about a manager or coworker, even if they genuinely really totally just suck as humans and everyone else would say so and it’s warranted and even their families would agree, shows an interviewer that you <em>can</em> talk shit. Which means you are <em>likely </em>talk shit. Which means you will probably <em>continue</em> to talk shit. Now <em>everyone</em> talks shit. Obviously. There’s not a lot better than talking shit. Especially about managers. They’re born to be talked shit about. But people who are obvious and at ease and up front about talking shit are not people other people like to have around. Especially not new job people. It means you gripe. It means you potentially stir up trouble. It means you have to potential to be negative. And it’s not something you want a hiring manager to know about you. Even if it’s true.</p><p>So, make everything you say about past jobs, managers, PMs, coworkers, CEOs, or whomever, <em>positive</em>. Bash respectfully. And constructively. Recall something decent about whomever you’re going to use in the above fishing question which is totally designed to get you to talk shit so they can know whether you’re the type to talk shit or not, and focus on how they got the best out of people by being blah blah blah. It may seem like a small detail but it’s a question of integrity and ethics. Both things you want hiring managers to think you have.</p><h4>Hiring managers and recruiters aren’t your friend.</h4><p>This sounds jaded but it’s true. I actually read these words verbatim in an article about recruiters and interviewing. Hiring managers are doing a job. They’re <em>people</em> people. They like talking. Or they pretend they do. They’re also salespeople, and most importantly they’re the first line of defence for a company. It’s their job to filter you out. They are tasked with finding out as much about you as possible in 15–30 minutes, which they glean through disarming conversation and reading between the lines of what you actually say. The laughs, the jokes, the efforts at connection, the understanding and empathizing, the nodding and “Oh ya, totally, I know how that goes, <em>kids</em>, am I right?” — it’s all an act. They are trying to decide whether you are valuable to them or not. They are trying to decide if you are trustworthy or not. They are trying to decide if you’re someone who will stick around for more than a year or not. It’s a lot (a LOT) like a first date. Which means, if you have any interest, you have to play ball.</p><p>As recruiters go, that’s a different animal, but it’s good enough to know they’re not cold calling/emailing you because they actually think your skills suit a job they’re trying to fill. It’s because they have a quota they are trying to make and you are a potential candidate that could add to their paycheck.</p><h4>Only apply to jobs you might actually want.</h4><p>This sounds trite. But it’s a bigger and more important point that it sounds. I’ve applied to places based only on the job posting title. I’ve applied to places on a bulk basis — like I need to fire off 5 of these today. I’ve applied to places based on ease — like only if the posting has the Linkedin “easy apply” button. While it might make you feel good and productive to click submit, if you actually hear back, and get an interview, you a) won’t remember what the job was, b) won’t give a shit, and c) won’t like actually want it, d) won’t do well in the interview if you make it to the interview, and e) will feel defeated when you get a rejection response because you’re not actually a good for the role in the first place (because you didn’t actually read the job description).</p><h4><strong>How you look is actually a factor.</strong></h4><p>This isn’t to say you have to be good looking. You don’t have to be fit. Or tall. Or handsome. But you do have to be clean. You have to have a relatively trimmed beard if you have a beard or stubble. On video, whatever clothes you wear make an impact on the interviewer who is judging you. Which is what they’re doing. Judging. The hoodie you’re wearing means you’re casual, you might or might not be serious, you’re likely a millenial, you have experience working remotely, you may or may not be wearing pants under the desk, you might be an upstart, you might be footloose and fancy free, you’re likely a free thinker, you might be opinionated, you might be difficult to work with, all to say you might not be a suitable candidate for stable, long term work at XYZ Industries.</p><p>No one will say this out loud though. Well, wait, all job posts now have that in the disclaimer at the bottom about equal opportunity and not having to be good looking etc etc. Which isn’t true. I mean it’s true if you ask them officially, but it’s not in the process of actually doing interviews.</p><p>Be clean. Be trimmed. Wear something that’s clean. If it’s a tech company and a dev job a hoodie is probably cool, sit in the middle of the screen, and take your video vibe seriously.</p><h4><strong>Sit up straight</strong></h4><p>I laugh when I read this back. It sounds hilarious. And it is. But it’s also part of the persona you’re selling. You are a product. You have an energy to you. You have a skillset and a value. Knowing you are valuable comes across in the way you carry your body. I’ve slouched and fidgeted for countless interviews. Leaning forward on crossed arms, swinging back and forth on my swivel chair, it all comes across as part of your vibe. A posture with calm awareness shows a person that has energy, that is awake, that is engaged, that is interested, and who actually gives a shit — both about life, and about the job they’re applying for. I might be reading a bit into it, but body language is one of those subconscious, and fully conscious things interviewers look at. Even if you don’t give a shit, paying attention to your body language will pay off in moving you to the next round. Besides, it just looks better.</p><h4>Have a decent video background</h4><p>This isn’t to say you need an all-white Oprah corner. Or that white Dollarstore glow donut thing. Just have a clean, relatively uncluttered background. I’ve done 50 interviews in my basement with all our kid junk, workout gear, and my guitars and basses in plain view. And not in a clean, organized way. In a chaotic way. Which most likely (100%) gets picked up by the interviewer as a part of your personality. Or part of your work persona. Or part of your productivity level. by And in my personal opinion, don’t use background blur or image replacement tech. <em>You can still see it’s your bedroom in your parents’ house with dirty clothes on your bed despite being blurred, ok?</em></p><p>And actually do the angles thing. Prop your laptop up on a box or something so it’s not pointed up. No one looks good from below. Be level or raised so the angle comes from above.</p><h4>Do a bit of research on the company</h4><p>The times I’ve gone through a few pages of the company website before an interview, the hiring manager is usually impressed. Worst case, you have a better idea of the product, the role, and a company’s website tells you a lot: whether they’re modern or in a modern space or not, if they value design, if they write well or explain what they do in a way that’s easy to understand, if they’re successful or not, and if they take their product and company seriously. A company that invests in a good website means they value their image and reputation. Or at least they pretend to. As a developer, you can also check out the tech they use, look at how fast or slowly their pages load, see if they have errors, analyze what UX/UI/design improvements you might make to their site, all of which can be very useful in the interview.</p><h4><strong>Don’t sound (or be) tired.</strong></h4><p>Everyone can tell if you’re tired. Or hungover. You don’t have to be Barry White but try to sound chipper, awake, relatively excited (not overly excited just normal excited). Plus if you’re tired you won’t think well on your feet. Or even remember anything.</p><h4>Don’t give a shit (or, take it with a grain of salt)</h4><p>After all this, you have to expect that 9/10 interviews won’t pan out. One company I applied to wrote “Fun fact, our CEO applied to 150 companies from 2012–2013 and never heard from a single one” in their initial response to my application. The ones that <em>almost</em> work out might entail 4 to 5 to 8 rounds (yes, I once did an interview with recruiters who used the “top grading” method which involved 8 rounds in the end) of further questions and projects and challenges and more meetings with higher level people, and <strong>THEN</strong> they don’t work out. That means the vast majority of interviews you do are a colossal, gargantuan, life sucking, depressing waste of time. It’s hard in light of this to keep on doing it. I think they call that the definition of insanity. But hey, we all need a job.</p><p>So that’s where scaling back your expectations can a) make life easier if and when you get another impersonal rejection letter (from a hiring manager who in the interview was laughing, sharing personal stories, talking about their kids, and virtually patting you on the back saying let’s go for beers, you’re awesome!), and b) actually give you an edge in the interview. When you aren’t desperate or trying too hard or coming off like you want it too badly, you’re less nervous, you seem cool, collected, in demand, not <em>needing </em>a job, but <em>choosing</em> a job. This plays well in all areas, especially when it comes to salary expectations.</p><h4>Treat it like dating.</h4><p>The first round interview is a date. Plain and simple. The first person to talk to you will know almost nothing about the job you’re applying for. S/he will be assessing you based on a list of questions they’ve been given (that they will 90% of the time read from a screen), <strong>but more so based on your personality</strong>. Your vibe. You’re energy. Their top question is are you a person anyone would want to work with (i.e. hang out with, manage, collaborate, partner) every single day? Which is the same as a date.</p><p>In the modern dating world you get one shot. It’s like Eminem. You either click or you don’t. There’s data somewhere on the amount of time it takes both women and men assess and conclude the viability of a date. It happens first visually. Then emotionally.</p><p>So you have to be cool, but not too cool or else you could care less about this bullshit job, fun but not too fun because work is serious, funny, but not too funny because no one likes a joker, modern, but not too modern because no one likes someone who <em>always</em> has to be modern, and skilled but not too skilled because then you’ll want more money than they want to pay.</p><h4>Challenges and Projects</h4><p>Tech interviews love to put candidates on the spot with coding challenges, verbal “what does this mean” or “how would you do this” questions, and projects that test your ability to reproduce designs or show skill. Part of this is normal, you have to have a sense for what a person can do. But part of it is bullshit and disrespectful. You don’t have to make people feel uncomfortable or put them on the spot by asking them to share their screen and solve a question designed to trip them up. Anyone can google how to loop over an array in Javascript, read back whether Javascript is asynchronous or synchronous, or explain what the reduce() method does (all of which I’ve been asked). There’s value to seeing how a person works through a problem but there are better ways. Some people don’t test well. Some people don’t do well being put on the spot. In live challenge situations, a tester is almost always evaluating a variety of criteria: how you work through something you don’t know, how long you take overall, how you act if you have trouble, and then the content of you actual answer.</p><p>But this all belies a more important point. As a candidate, you are almost never compensated for the time you spend either doing a multi-day project, or doing a live test,, or doing a jillion interviews for that matter. You’re putting yourself in the hot seat, for free, of your own will, and just taking the punches. Now, you obviously have to jump through some hoops to get a job? But you also don’t. Not every job is for you. It’s fair and also shows self-respect and self-knowledge to say <em>no</em>. Or say is there another way to do this? “I’m sorry I just don’t test well on the spot and feel my skillset isn’t valued in this type of context — so if there’s another way we can do this I’d be happy to come up with something.”</p><p>Live challenges miss a gigantic amount of a person’s value and ability. Can you learn on your own? Can you learn new things quickly? Do you have passion? Are you motivated? Are you easy to work with? Are you funny, nice, cool, a person other people would want to be around? Skills are just skills; they’re learnable.</p><blockquote><strong>If there’s one skill a developer can be said to need, it’s the ability to learn.</strong></blockquote><p>Languages, frameworks, specifications, accessibility standards, and browser compatibilities change weekly if not faster. If you stopped coding for a month you’d have to work to get back up to speed on what’s new. Imagine a year.</p><h4>Be easy.</h4><p>Even if you’re applying for a management or director role, you will be working under someone else. Which means you will be managed. Which means you have to be able to take direction, take feedback, and work with people. <em>Being easy to work with might be one of the all time top employee strengths and reasons for being hired or well recommended.</em> One of the areas I personally have most likely failed in at interviews is coming across as wanting to be and do more than the role allows. I’ve asked if a company is open to a complete technology revamp based on what I want and like to use. I’ve told hiring managers that I like wearing all the hats, design, development, project management, content creation, etc. Which then prompts the question, <em>how do you find you collaborate and work with other people? </em>This isn’t to say don’t have initiative or show ambition. But it does behoove you to know the bounds of the role you’re applying for, and to generally be easy going. Showing you can toe the line when needed, take direction, smile and be positive is a big plus for a potential employee.</p><h4>Salary expectations</h4><p>Fuck. This is maybe the worst and most difficult question to field in an interview. In a nutshell I try to have a target range within 10k. For a while I was using one target number that was at the high or higher end my ideal range, then following up by saying I’m negotiable. Every job and every company has an ideal budget. It’s likely in the interest of the hiring manager to get you for as cheap as possible. Though that’s not always the case. Some jobs in 2023 will actually include a salary range in the posting which is really nice as a candidate. Otherwise it’s always a crap shoot whether they want to pay 50k or 110.</p><p>Look up your job, some variations on the title, and different experience levels (mid, senior, etc) on Glassdoor and other sites to get a comparison. Your “Market value” is a thing and companies will know what range other companies are paying for your position.</p><p>That being said, shoot for the moon. It shows you value yourself to ask for a good salary. At least the very least, ask for what you would actually take to do the job. Remember you’ll be doing it every single day. With the same people. The same managers. The same 3 weeks of vacation. The same morning meetings. Lowballing yourself just hurts <em>you</em> in the end.</p><h4>Conclusion</h4><p>So, there you go. Interviews suck. But hopefully this hard won list of helpers can give you a bit of an edge in getting that job you don’t really want but need to pay your bills.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f03d404ca94b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get the estimated read time of your blog post with Javascript]]></title>
            <link>https://medium.com/@andrewmasonmedia/how-to-get-the-estimated-read-time-of-your-blog-post-with-javascript-c14765712923?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/c14765712923</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[blogging]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Mon, 08 May 2023 14:55:37 GMT</pubDate>
            <atom:updated>2023-05-08T14:55:37.022Z</atom:updated>
            <content:encoded><![CDATA[<p>Medium does this for you automatically. But what if you have your own blog that doesn’t? With a little Javascript it’s pretty easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bAu3BFvBvuevegDD" /><figcaption>Photo by <a href="https://unsplash.com/@billy_huy?utm_source=medium&amp;utm_medium=referral">Billy Huynh</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Intro</h4><p>I’m building a blog for myself using Vue 3 and Bootstrap. While there are plugins for everything these days it’s pretty fun and not too hard to build out a lot of the same functionality: listing latest posts, category filtering, pagination, etc. One feature though that most modern blogging platforms offer natively that seemed like a good idea is an estimated read time for posts. How do you do that?</p><h4>Thought process</h4><p>Instead of going to Stackoverflow or my new AI dev search engine, I approached it as a logic problem. Just to see if my thinking made sense.</p><h4>Read rate</h4><p>To get read time, you first need a little internet help to find out <a href="https://infusion.media/content-marketing/how-to-calculate-reading-time/">how long it takes the average person</a> to read X number of words. Turns out there’s a general consensus around 200–250. For students or people that are practiced at reading quickly, that can go up to 300. For now I’ll use 225 for a middle ground.</p><h4>Word count</h4><p>Next you have to find out how many words are in your article. That involves <a href="https://stackoverflow.com/questions/6543917/count-number-of-words-in-string-using-javascript">counting the length of the string</a> that is your post. You can do this a few ways, but combining the javascript match()<a href="https://www.w3schools.com/jsref/jsref_match.asp">method</a> and a regular expression, you can return that as a number.</p><h4>Word count / read rate</h4><p>Then we want to divide the total word count by the read rate to give us a timeframe. Doing raw division works, but it’ll give us a messy, multi-decimal remainder. We can remove the remainder and get the “integer” part of the total number using Math.trunc() <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc">method</a> or use the Math.ceil() <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil">method</a> which <em>“always rounds up and returns the smaller integer greater than or equal to a given number.”</em> i.e. .95 will round up to 1. -7.04 will round down to -7. Don’t ask me why. I’ll use Math.trunc() to keep it simple:</p><h4>Examples</h4><p>It’s import to note that because both Math.trunc() and Math.ceil() will remove the decimal and round down respectively, if you try this function with a short string/post, i.e. a test string, or anything that is LESS than one minute, the read time will return as ZERO. That’s why the words string below is pretty long.</p><pre>const words = &quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Pulvinar proin gravida hendrerit lectus a. Eu augue ut lectus arcu bibendum at. Vitae semper quis lectus nulla at volutpat. Etiam sit amet nisl purus. Sit amet cursus sit amet. Scelerisque fermentum dui faucibus in ornare quam. Velit egestas dui id ornare arcu odio ut sem nulla. Facilisi nullam vehicula ipsum a arcu. Sed id semper risus in hendrerit gravida rutrum. At tellus at urna condimentum mattis pellentesque id. Quis auctor elit sed vulputate mi sit amet mauris. Sit amet tellus cras adipiscing enim eu turpis egestas. Vulputate eu scelerisque felis imperdiet proin fermentum leo vel orci. Blandit aliquam etiam erat velit scelerisque in dictum non consectetur. Aliquam sem et tortor consequat. Scelerisque in dictum non consectetur a erat nam at. Id porta nibh venenatis cras sed felis eget velit. Ullamcorper a lacus vestibulum sed arcu non odio euismod. Mollis nunc sed id semper risus in. Vitae congue mauris rhoncus aenean vel elit scelerisque mauris. Volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque in. Bibendum est ultricies integer quis auctor elit sed vulputate mi. Egestas congue quisque egestas diam in arcu cursus euismod. Facilisis volutpat est velit egestas. Ut placerat orci nulla pellentesque dignissim enim sit amet. Donec enim diam vulputate ut. Morbi tristique senectus et netus et malesuada fames ac turpis. Morbi blandit cursus risus at ultrices mi tempus imperdiet. Condimentum id venenatis a condimentum vitae sapien pellentesque habitant morbi. Vitae justo eget magna fermentum iaculis eu non diam. Vitae tortor condimentum lacinia quis vel eros donec ac. Libero id faucibus nisl tincidunt eget nullam non. Eu mi bibendum neque egestas congue. Ornare aenean euismod elementum nisi quis eleifend quam adipiscing. In aliquam sem fringilla ut morbi. Elit scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique. Integer quis auctor elit sed vulputate mi sit amet mauris. Condimentum lacinia quis vel eros donec ac odio tempor. Malesuada fames ac turpis egestas sed tempus urna et pharetra. Curabitur gravida arcu ac tortor dignissim convallis. Malesuada nunc vel risus commodo viverra maecenas. Ut diam quam nulla porttitor. Fermentum posuere urna nec tincidunt praesent. Scelerisque mauris pellentesque pulvinar pellentesque habitant.&quot;<br><br>function readTime() {<br>  const totalWords = words.match(/(\w+)/g).length;<br>  const readMins = Math.trunc(totalWords / 225);<br>  alert(readMins);<br>}<br><br>readTime();<br><br>// returns<br>1</pre><p>Now if we want to make the function <a href="https://stackoverflow.com/questions/6543917/count-number-of-words-in-string-using-javascript">reusable</a>, we can add a strparameter so we can pass in a post key from our total posts array which will run the function on whichever post is being loaded dynamically:</p><pre>function readTime(str) {<br>  const words = str.match(/(\w+)/g).length;<br>  const readMins = Math.trunc(words / 250);<br>  return readMins;<br>}</pre><p>So here’s a functional example with Vue 3 (Composition API) using <a href="https://medium.com/@andrewmasonmedia/dynamic-routing-with-route-params-in-vue-3-30270b82919f">dynamic routing</a> via a computed property, and data from a local JSON file (using some basic Bootstrap classes for styling):</p><pre>// BlogPostDetail.vue<br><br>&lt;script setup&gt;<br><br>import { computed } from &#39;vue&#39;;<br>import { useRoute } from &#39;vue-router&#39;;<br>import posts from &#39;../data/posts.json&#39;<br><br>const route = useRoute();<br><br>const post = computed(() =&gt; {<br>  return posts.blog.find(post =&gt; post.id === route.params.id)<br>})<br><br>function readTime(str) {<br>  const words = str.match(/(\w+)/g).length;<br>  const readMins = Math.trunc(words / 250);<br>  return readMins;<br>}<br><br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-12&quot;&gt;<br>        &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>        &lt;h5&gt;{{ &#39;Estimated read time &#39; + readingTime(post.body + post.title) + &#39; mins&#39; }}&lt;/h5&gt;<br>        &lt;p v-html=&quot;post.body&quot;&gt;&lt;/p&gt;<br>       &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;template&gt;</pre><h4>Conclusion</h4><p>Having an “estimated read time” on your blog posts is a nice little convenience for readers. It’s also grown to be an expected feature. Hopefully this little snippet can take some of the work out of it for you.</p><p>For a more thorough look at dynamic routing in Vue 3 check out my previous post <a href="https://medium.com/@andrewmasonmedia/dynamic-routing-with-route-params-in-vue-3-30270b82919f">here</a>.</p><p>If this helps you or you have any comments or thoughts on how this can be done better please comment and let me know!</p><blockquote><em>If you like this post, feel free to </em><a href="https://www.buymeacoffee.com/bassfx"><em>buy me a coffee</em></a><em>, and don’t forget to subscribe and check out more posts on my </em><a href="https://medium.com/@andrewmasonmedia"><em>medium home page</em></a><em>. Reach out and get more info on my </em><a href="https://andrewmasonmedia.com/"><em>website</em></a><em> (built with Vue 3, the Medium </em><a href="https://rss2json.com/"><em>rss2feed</em></a><em>, Bootstrap 5, and GSAP).</em></blockquote><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c14765712923" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use images with Vite and Vue]]></title>
            <link>https://medium.com/@andrewmasonmedia/how-to-use-images-with-vite-and-vue-937307a150c0?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/937307a150c0</guid>
            <category><![CDATA[image]]></category>
            <category><![CDATA[vitejs]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Wed, 12 Apr 2023 18:31:14 GMT</pubDate>
            <atom:updated>2023-11-07T00:29:21.523Z</atom:updated>
            <content:encoded><![CDATA[<p>Using local and dynamic images in Vite is more confusing than you’d think (or at least more confusing than I thought). If you have a url that links to Unsplash or Pexels, you can just use your standard &lt;img&gt; tag with the src. But if you want to pull in an image from your assets folder you have to go a different route. I’ll be using Vue 3 and the composition API for this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g9X7qKne9VUyXcj3" /><figcaption>Photo by <a href="https://unsplash.com/@joseadd?utm_source=medium&amp;utm_medium=referral">JOSE LARRAZOLO</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Intro</h4><p>You’ve basically got 3 different ways to do it. Put images in the public folder and reference them normally (just a forward slash and the image name). Import images directly into your view/project and use them in your template. Use the native ESM import.meta.url to assign images to variables, or create a function to use multiple images more easily. I’ll follow up at the end about referencing images from an API.</p><h4>1. Public folder</h4><p>The simplest solution is to put your assets into the <a href="https://vitejs.dev/guide/assets.html#the-public-directory">public folder</a>, and then reference them as you normally would.</p><pre>// add circle.svg to the public directory<br>// public images are served at the root path so you only need &#39;/&#39; + your image path<br><br>&lt;img src=&quot;/circle.svg&quot;&gt;</pre><h4>2. Import files individually</h4><p>You can import each image you need as a variable that can then be referenced where you need it. The obvious drawback to this is if you have multiple images.</p><pre>&lt;script setup&gt;<br>import imgUrl from &#39;./assets/img.png&#39;<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;img :src=&quot;imgUrl&quot; /&gt;<br>&lt;/template&gt;<br></pre><h4>3. Import images with import.meta.url</h4><blockquote><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta">import.meta.url</a> is a native ESM feature that exposes the current module’s URL. Combining it with the native <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL">URL constructor</a>, we can obtain the full, resolved URL of a static asset using relative path from a JavaScript module:</blockquote><p>More on this from the Vite docs <a href="https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url">here</a>.</p><ol><li>Similar to example #2, you assign your image path to a constant and then use it in your template. *Be aware you have to write out the entire path to the file i.e. ./assets/img.png:</li></ol><pre>&lt;script setup&gt;<br>const imgUrl = new URL(&#39;./assets/img.png&#39;, import.meta.url).href<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;img :src=&quot;imgUrl&quot; /&gt;<br>&lt;/template&gt;</pre><p>2. Dynamically import images using a function and template literals</p><blockquote>*I’ve found this to be the most useful approach, especially with multiple images.</blockquote><p>Be aware, in the Vite docs, the ./dir/ part of the path is a placeholder — update it to the path and folder of your project.</p><pre>// from the docs<br>function getImageUrl(name) {<br>  return new URL(`./dir/${name}.png`, import.meta.url).href<br>}<br><br>// updated with your project&#39;s assets folder setup<br>function getImageUrl(name, ext) {<br>  return new URL(`../assets/img/${name}.png`, import.meta.url).href<br>}<br><br>// works with svg and other file formats as well<br>function getImageUrl(name) {<br>  return new URL(`../assets/img/${name}.svg`, import.meta.url).href<br>}</pre><p>3. You can also define a second parameter in the function so the image extension can be dynamic as well i.e. .jpg, .png, .svg etc.</p><pre>&lt;script setup&gt;<br>// where &#39;name&#39; is the actual name of the file, and &#39;ext&#39; is the extension<br>// i.e. myjpg.jpg<br><br>function getImageUrl(name, ext) {<br>  return new URL(`./assets/img/${name}.${ext}`, import.meta.url).href<br>}<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;img :src=&quot;getImageUrl(&#39;myjpg&#39;,&#39;jpg&#39;)&quot; alt=&quot;&quot;&gt;<br>  &lt;img :src=&quot;getImageUrl(&#39;mysvg&#39;,&#39;svg&#39;)&quot; alt=&quot;&quot;&gt;<br>&lt;/template&gt;</pre><h4>4. Using dynamic images from an API</h4><p>Using images from an API doesn’t require any special treatment outside of normal data rendering in Vue. Just make your API request, get your data, and render it in the template.</p><pre>&lt;script setup&gt;<br>import { ref } from &#39;vue&#39;<br><br>// declare an empty array variable to hold your data<br>const photos = ref([]);<br><br>//create a function to fetch your data<br>function getImages() {<br>  fetch(&#39;https://jsonplaceholder.typicode.com/albums/1/photos&#39;)<br>  .then(response =&gt; response.json())<br>  .then((data) =&gt; {<br>    photos.value = data;<br>    console.log(data)<br>  })<br>}<br><br>getImages();<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  // loop over photos array with some bootstrap classes for styling<br>  &lt;div class=&quot;container&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-3&quot; v-for=&quot;(item, index) in photos&quot; <br>      :key=&quot;index&quot;&gt;<br>        &lt;img :src=&quot;item.url&quot; class=&quot;w-100&quot;&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><h4>5. Dynamic inline background images</h4><p>I’ll add a little extra section here to quickly run over using dynamic background images with inline style tags. I’ll use the same function approach as in example #3.3, but use it inline.</p><pre><br>&lt;script setup&gt;<br>// where &#39;name&#39; is the actual name of the file, and &#39;ext&#39; is the extension<br>// i.e. myjpg.jpg<br><br>function getImageUrl(name, ext) {<br>  return new URL(`./assets/img/${name}.${ext}`, import.meta.url).href<br>}<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container&quot;&gt;<br>    &lt;div class=&quot;row&quot; :style=&quot;{&#39;background&#39; : &#39;url(https://medium.com/&#39;+%20getImageUrl(&#39;myjpg&#39;,&#39;jpg&#39;) +&#39;)&#39;, &#39;background-size&#39; : &#39;cover&#39;}&quot;&gt;<br>      &lt;div class=&quot;col-lg-3&quot;&gt;<br>        &lt;h1&gt;Background images!&lt;/h1&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><h4>Conclusion</h4><p>Using images with Vite and Vue seemed like a head scratcher initially. I still don’t fully understand why it’s so counterintuitive when referencing local and/or dynamic assets. But hopefully this gives you a better idea. Again, I found the approach of using a function with dynamic file name and extension parameters to work best for multiple images with different formats. Be sure to check out the Vite docs for more info.</p><blockquote>If you like this post, feel free to <a href="https://www.buymeacoffee.com/bassfx">support my work</a>, and don’t forget to subscribe and check out more posts on my <a href="https://medium.com/@andrewmasonmedia">medium home page</a>. Reach out and get more info on my <a href="https://andrewmasonmedia.com/">website</a> (built with Vue 3, the medium <a href="https://rss2json.com/">rss2feed</a>, Bootstrap 5, and GSAP).</blockquote><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=937307a150c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic Routing with Route Params in Vue 3]]></title>
            <link>https://medium.com/@andrewmasonmedia/dynamic-routing-with-route-params-in-vue-3-30270b82919f?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/30270b82919f</guid>
            <category><![CDATA[navigation]]></category>
            <category><![CDATA[dynamic-routing]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vue-3]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 18:31:21 GMT</pubDate>
            <atom:updated>2023-05-02T18:40:38.738Z</atom:updated>
            <content:encoded><![CDATA[<p>The basics of dynamic routing in Vue are relatively straightforward, but the documentation, available examples, and popular tutorials are a bit hard to make sense of, especially when it comes to dynamic routing with <em>dynamic data</em> (i.e. data coming from an API). There are also differences from Vue 2 as well as a raft of small problems I ran into that took time to figure out. Here’s what I found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4CuKlNSLqgsFzNzb" /><figcaption>Photo by <a href="https://unsplash.com/@jan_huber?utm_source=medium&amp;utm_medium=referral">Jan Huber</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Intro</h4><p>For this article we’ll use a blog as an example. We’ll create one page/view to list all the posts, and another page to be the dynamic “Detail” template that displays the content of each individual post. The post data will come from two examples, a single local JSON file (an array of objects) and an API with the same data. We’ll use Vue 3 and the Composition API, computed properties to find and match route params with the data, and the fetch() method for GETting our same data from an API.</p><h4>Static routing</h4><p>It’s not technically called “static”, but the usual mode of navigating between pages (routes) in a Vue application that are individually hard coded is an example of static routing. The name, path, and any other attributes of a route stay the same. When you need a new page, you create a new view, and open up router/index.js, and type out a new route path.</p><h4>Dynamic routing essentials</h4><p>Dynamic routing is when your application routes (or part of your app) get created on request by/from a data source: in most cases either a local JSON file or dynamic data from an API. Dynamic routing is readily exemplified in blogs and CMSs, news and tech applications, and ecommerce sites: where you have a large number of items (posts, products, articles) that can be displayed in the same way.</p><p>Dynamic routing removes the need to manually declare your routes (or update your layout) which makes an application vastly more scalable, and manageable by a user or non-tech client.</p><h4>There are three core parts to it:</h4><ol><li>Declare a dynamic route in your router/index.js file.</li><li>Create a view/page that will render all your data as a list or grid of individual items (think like a page showing all posts or products). Import your data source and create dynamic router-links that will take care of the dynamic navigation to the next step, a dynamic “detail” page.</li><li>Create another view/page that will act as a template for the details of each individual item. This page will be populated dynamically. The layout stays more or less the same, but the content is swapped out based on the route parameter.</li></ol><h4>Data Sources</h4><p>As mentioned, there are two basic ways to source data: a local file, or a remote API. We’ll start with local JSON data and follow up with how to route dynamically with data from an API.</p><h4>Local JSON file</h4><p>First let’s go through the steps of setting up dynamic routing with local data.</p><blockquote>You want to structure your data as a JSON array of objects. Each object needs to have a unique key to use as a route parameter. Route params are how the router matches and populates a dynamic route with its corresponding data. Very often each object has a unique id but other keys can be used as well: title, slug, date, etc. The value of this key will become the slug in your url: i.e. blog/1, or blog/my-first-post. Be aware that the best value to use is one word, or a number. Multiple word values should be separated by dashes and not contain special characters (brackets, colons, etc).</blockquote><ol><li>Create a JSON file.<br>I like to create a data folder in the src directory and put all the JSON into a posts.json file inside it. (I copied the first 9 entries below from <a href="https://jsonplaceholder.typicode.com/posts">json placeholder</a> to use as our static local data. We’ll use the live API for our dynamic data).</li></ol><pre>// data/posts.json<br><br>[<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 1,<br>    &quot;title&quot;: &quot;sunt aut facere repellat provident occaecati excepturi optio reprehenderit&quot;,<br>    &quot;body&quot;: &quot;quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 2,<br>    &quot;title&quot;: &quot;qui est esse&quot;,<br>    &quot;body&quot;: &quot;est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 3,<br>    &quot;title&quot;: &quot;ea molestias quasi exercitationem repellat qui ipsa sit aut&quot;,<br>    &quot;body&quot;: &quot;et iusto sed quo iure\nvoluptatem occaecati omnis eligendi aut ad\nvoluptatem doloribus vel accusantium quis pariatur\nmolestiae porro eius odio et labore et velit aut&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 4,<br>    &quot;title&quot;: &quot;eum et est occaecati&quot;,<br>    &quot;body&quot;: &quot;ullam et saepe reiciendis voluptatem adipisci\nsit amet autem assumenda provident rerum culpa\nquis hic commodi nesciunt rem tenetur doloremque ipsam iure\nquis sunt voluptatem rerum illo velit&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 5,<br>    &quot;title&quot;: &quot;nesciunt quas odio&quot;,<br>    &quot;body&quot;: &quot;repudiandae veniam quaerat sunt sed\nalias aut fugiat sit autem sed est\nvoluptatem omnis possimus esse voluptatibus quis\nest aut tenetur dolor neque&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 6,<br>    &quot;title&quot;: &quot;dolorem eum magni eos aperiam quia&quot;,<br>    &quot;body&quot;: &quot;ut aspernatur corporis harum nihil quis provident sequi\nmollitia nobis aliquid molestiae\nperspiciatis et ea nemo ab reprehenderit accusantium quas\nvoluptate dolores velit et doloremque molestiae&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 7,<br>    &quot;title&quot;: &quot;magnam facilis autem&quot;,<br>    &quot;body&quot;: &quot;dolore placeat quibusdam ea quo vitae\nmagni quis enim qui quis quo nemo aut saepe\nquidem repellat excepturi ut quia\nsunt ut sequi eos ea sed quas&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 8,<br>    &quot;title&quot;: &quot;dolorem dolore est ipsam&quot;,<br>    &quot;body&quot;: &quot;dignissimos aperiam dolorem qui eum\nfacilis quibusdam animi sint suscipit qui sint possimus cum\nquaerat magni maiores excepturi\nipsam ut commodi dolor voluptatum modi aut vitae&quot;<br>  },<br>  {<br>    &quot;userId&quot;: 1,<br>    &quot;id&quot;: 9,<br>    &quot;title&quot;: &quot;nesciunt iure omnis dolorem tempora et accusantium&quot;,<br>    &quot;body&quot;: &quot;consectetur animi nesciunt iure dolore\nenim quia ad\nveniam autem ut quam aut nobis\net est aut quod aut provident voluptas autem voluptas&quot;<br>  }<br>]</pre><p>2. Create your new routes: add one for your blog posts /blog (which will route to BlogPosts.vue) and another that will be the dynamic route path for each individual post, /blog/:id. Open up your router/index.jsand add this:</p><pre>// router/index.js<br><br>import { createRouter, createWebHistory } from &#39;vue-router&#39;<br>import HomeView from &#39;../views/HomeView.vue&#39;<br><br>const router = createRouter({<br>  history: createWebHistory(import.meta.env.BASE_URL),<br>  routes: [<br>    // don&#39;t need this, but I added a stock home/welcome page<br>    {<br>      path: &#39;/&#39;,<br>      name: &#39;Home&#39;,<br>      component: HomeView<br>    },<br>    // page for all posts<br>    {<br>      path: &#39;/blog&#39;,<br>      name: &#39;Blog&#39;,<br>      component: () =&gt; import(&#39;../views/BlogPosts.vue&#39;)<br>    },<br>    // page for each post to be dynamically rendered<br>    {<br>      path: &#39;/blog/:id&#39;,<br>      name: &#39;Detail&#39;,<br>      component: () =&gt; import(&#39;../views/BlogDetail.vue&#39;)<br>    },<br>  ]<br>})<br><br>export default router</pre><p>3. Create your new pages.<br>In the views folder, add a new file, BlogPosts.vue. This will display all your posts. Then create another called BlogDetail.vue. This will display each individual post.</p><p>4. Set up BlogPosts.vue: import your data from the local JSON file — posts.json</p><pre>// views/BlogPosts.vue<br><br>&lt;script setup&gt;<br>import postData from &#39;../data/posts.json&#39;<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>// We&#39;ll fill this in a minute<br>&lt;/template&gt;</pre><p>4. Render all your posts on the page. I’m using v-forto loop over the data and some basic Bootstrap classes to style the posts in a 3 column grid.</p><pre>// views/BlogPosts.vue<br><br>&lt;script setup&gt;<br>import postData from &#39;../data/posts.json&#39;<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container-fluid&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-4&quot; v-for=&quot;(post, index) in postData&quot; :key=&quot;index&quot;&gt;<br>        &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>        &lt;p&gt;{{ post.body }}&lt;/p&gt;<br>        &lt;button&gt;Read more&lt;/button&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>5. Set up links to navigate to your individual posts using router-links with dynamic paths.</p><pre>// views/BlogPosts.vue<br><br>&lt;script setup&gt;<br>import postData from &#39;../data/posts.json&#39;<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container-fluid&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-4&quot; v-for=&quot;(post, index) in postData&quot; :key=&quot;index&quot;&gt;<br>        &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>        &lt;p&gt;{{ post.body }}&lt;/p&gt;<br><br>        // add a dynamic path to the router-link<br>        &lt;router-link :to=&quot;&#39;/blog/&#39; + post.id&quot;&gt;<br>          &lt;button&gt;Read more&lt;/button&gt;<br>        &lt;/router-link&gt;<br><br>        // you can also use a template literal = same result<br>        &lt;router-link :to=&quot;`/blog/${post.id}`&quot;&gt;<br>          &lt;button&gt;Read more&lt;/button&gt;<br>        &lt;/router-link&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><h4>The trickier parts:</h4><p>Now we have to do the functional work of dynamically matching the parameter you declared in your route (i.e. /blog/:id), with the corresponding individual object in your data. This is how the router will know to insert a new value into the url and then fetch the corresponding data from your JSON file to populate the BlogDetail.vue page template.</p><blockquote>As a caveat, I find this part the most confusing and also confused when it comes to routing tutorials and the Vue community. Most of them glaze over or only quickly explain how this works, why it works, and especially, what doesn’t work. And to be honest I don’t know the exact ins and outs but I’ll do my best to explain how I understand it.</blockquote><h4>Computed properties</h4><p>From the Vue docs:</p><blockquote>“…for complex logic that includes reactive data, it is recommended to use a computed property…You can data-bind to computed properties in templates just like a normal property. Vue is aware that [your computed property function] depends on [a data source or specific value] so it will update any bindings that depend on [your computed property] whenever the data changes.”</blockquote><p>For example, a computed property will run a function or some logic on whatever value you declare, and return a result. In our case we want it to filter and/or find the parameter we set in our router, and match it to our JSON data source to return a single object: i.e. a single blog post.</p><p>6. In our BlogDetail.vue page, let’s set up a computed property to match our dynamic routes with our data. <br>In Vue 3 we have to import computed from vue. To use route params we also have to import the useRoute() function from the vue-router.</p><pre>// BlogDetail.vue<br><br>&lt;script setup&gt;<br>import { computed } from &#39;vue&#39;; // import computed<br>import { useRoute } from &quot;vue-router&quot;; // import route<br>import postData from &#39;../data/posts.json&#39;; // import our data<br><br>// declare useRoute() a constant so we can use the route params <br>// more easily in the template<br>const route = useRoute();<br><br>// declare your computed function =&gt; we use the .find() method <br>// to search our data for an &#39;id&#39; key that matches the route parameter we set<br>// in our router/index.js file i.e. /blog/:id<br><br>const post = computed(() =&gt; {<br>  return postData.find(post =&gt; post.id === route.params.id)<br>})<br>&lt;/script&gt;<br></pre><blockquote><em>So what happens is the computed property runs </em><em>.find() on the </em><em>postData. It searches through all the posts for the </em><em>id key. When you click on any of the posts listed on the main </em><em>BlogPosts.vue page (all of which come from the </em><em>postData.json file and all of which have unique IDs), the router navigates to our dynamic template (with an </em><em>id in the url that matches the id of the post you selected), and the computed function inside the </em><em>BlogDetail.vue page retrieves the corresponding data from that specific id, and populates it into the template.</em></blockquote><p>For reference we can also use the Javascript .filter()method to match posts and ids.</p><pre>// The .find() method returns the array element value (if any) <br>// of the elements in the array that satisfy a specified condition.<br>// Since it returns the value itself, it doesn&#39;t require a loop to access.<br><br>const post = computed(() =&gt; {<br>  return postData.find(post =&gt; post.id === route.params.id)<br>})<br><br>// The filter() method returns an array with the matched value inside.<br>// This means we need to loop over the array to access the value.<br>// If we add the [0] at the end of the function, it specifies we want just the <br>// first value in the array, then we don&#39;t need to loop over it.<br><br>const post = computed(() =&gt; {<br>    return postData.filter(post =&gt; post.id === route.params.id)[0];<br>})</pre><p>7. Now we can use our post computed property to render the data from each individual post (again using Bootstrap classes for styling):</p><pre>// BlogDetail.vue<br><br>&lt;script&gt;<br>import { computed } from &#39;vue&#39;;<br>import { useRoute } from &quot;vue-router&quot;;<br>import postData from &#39;../data/posts.json&#39;;<br><br>const route = useRoute();<br><br>const post = computed(() =&gt; {<br>  return postData.find(post =&gt; post.id === route.params.id)<br>})<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container-fluid&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-12&quot;&gt;<br>         &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>         &lt;p&gt;{{ post.body }}&lt;/p&gt;<br>       &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><blockquote>Now you should have a main posts page that shows all your posts in a grid, as well as a functioning detail page that shows the content of each individual post.</blockquote><h4>Dynamic Routing with Dynamic Data: fetching data from an API</h4><p>Using an API for your data source in dynamic routing isn’t on paper that much different from local data. That being said, there are small things to take into account that will make it or break it.</p><p>We have to walk back to Step 4: importing your data.</p><p>Instead of a simple import statement that brings in data from your local JSON file, we need to make an API call to retrieve our data from a remote source. In this case we’ll use the fetch() method to make a GET request to the <a href="https://jsonplaceholder.typicode.com/posts/">json placeholder API</a>. We’ll use the /posts endpoint which will return the same data we hard coded into our JSON file above.</p><p><strong>First</strong> we import ref and onMounted from vue. ref is a reactive object (i.e. state). We set it to be an empty array which will hold our post data after it’s been fetched (it can hold different values, like objects, strings, booleans, and null). More on ref <a href="https://blog.logrocket.com/reactivity-vue-3-composition-api-ref-reactive/#vue-ref">here</a>. It’s the same as when we declare an empty variable in the Options API using the data() option.</p><blockquote>*An important note is that to access the value of the object, you have to use .value when referring to the ref: i.e. postData.value will return your posts data whereas postData by itself will be undefined.</blockquote><pre>// BlogPosts.vue<br><br>&lt;script setup&gt;<br>import { ref, onMounted } from &#39;vue&#39;;<br><br>// set an empty reactive object (in this case an array) to hold our post data<br>const postData = ref([]);<br><br>const base_url = &quot;https://jsonplaceholder.typicode.com/posts/&quot;;<br>async function getPosts() {<br>    let response = await fetch(base_url);<br>    postData.value = await response.json();<br>    console.log(postData.value)<br>  }<br><br>// execute the getPosts() function in onMounted<br>onMounted(() =&gt; {<br>    getPosts();<br>})<br>&lt;/script&gt;</pre><p>So now we’re calling our API and should be getting back an array of objects which fills our dynamic ref variable. Since we’re assigning our data to the same name i.e. postData everything else on this page stays the same:</p><p><em>*Note that like our static JSON data, I’ll use the </em><em>slice() method inside the </em><em>v-for to loop over just the first 9 values in the array so we don’t get 100 posts on the page.</em></p><pre>// BlogPosts.vue<br><br>&lt;script setup&gt;<br><br>import { ref, onMounted } from &#39;vue&#39;;<br><br>// set an empty reactive object (in this case an array) to hold our post data<br>const postData = ref([]);<br><br>const base_url = &quot;https://jsonplaceholder.typicode.com/posts/&quot;;<br>async function getPosts() {<br>    let response = await fetch(base_url);<br>    postData.value = await response.json();<br>    console.log(postData.value)<br>  }<br><br>// execute the getPosts() function in onMounted<br>onMounted(() =&gt; {<br>    getPosts();<br>})<br>&lt;/script&gt;<br><br>// loop over data and render in the template<br>&lt;template&gt;<br>  &lt;div class=&quot;container-fluid&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-4&quot; v-for=&quot;(post, index) in postData.slice(0,8)&quot; :key=&quot;index&quot;&gt;<br>        &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>        &lt;p&gt;{{ post.body }}&lt;/p&gt;<br><br>        // add a dynamic path to the router-link<br>        &lt;router-link :to=&quot;&#39;/blog/&#39; + post.id&quot;&gt;<br>          &lt;button&gt;Read more&lt;/button&gt;<br>        &lt;/router-link&gt;<br><br>        // you can also use a template literal = same result<br>        &lt;router-link :to=&quot;`/blog/${post.id}`&quot;&gt;<br>          &lt;button&gt;Read more&lt;/button&gt;<br>        &lt;/router-link&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><h4>Rendering individual posts</h4><p>Here’s the next rub. We can’t use the computed property we ran before on our local data. We need instead to append our route.params to our API endpoint to facilitate navigating dynamically through our data. Since we’re using the id of each post as our route and route parameter, each id creates a new url that renders only the data for <em>that</em> object. The trick is that the url is an actual active url/endpoint on the json placeholder API. If you visit <a href="https://jsonplaceholder.typicode.com/posts/1">https://jsonplaceholder.typicode.com/posts/1</a> you get the data only of the first post. If you visit <a href="https://jsonplaceholder.typicode.com/posts/1">https://jsonplaceholder.typicode.com/posts</a>/ you get all posts.</p><p>This is where it gets grey in most tutorials. If you tried to access :slug, for example, you’d get an undefined error because “the resource” doesn’t exist.</p><p>If your endpoint is a file (like a .json file in a github repo and published to github pages), or a random generated url from a headless CMS type service, appending an id to the end of the url <strong>will not work </strong>for dynamic routing. Because that url/resource doesn’t exist. <em>More on this below.</em></p><p>So we need to define another ref, import useRoute() to access route.params, fetch our data again, and this time append the route.params to the endpoint url.</p><p><strong>*Another important factoid: the </strong><strong>ref in the detail page can’t be another array or else you’ll have to loop over it. Set its value to an object (which it will be) or an empty string.</strong></p><pre>// BlogDetail.vue<br><br>&lt;script setup&gt;<br><br>import { ref, onMounted } from &#39;vue&#39;;<br>import { useRoute } from &#39;vue-router&#39;;<br><br>// access route for route params<br>const route = useRoute();<br><br>// set an empty ref (in this case an object) to hold our individual <br>// post data<br>const post = ref({});<br><br>// fetch your data with params<br>const base_url = &quot;https://jsonplaceholder.typicode.com/posts/&quot;;<br>async function getPostDetail() {<br>    let response = await fetch(base_url + route.params.id);<br>    post.value = await response.json();<br>    console.log(post.value)<br>  }<br><br>// execute the getPostDetail() function in onMounted<br>onMounted(() =&gt; {<br>    getPostDetail();<br>})<br><br>// The getPostDetail() function can also run immediately and doesn&#39;t have <br>// to be in the onMounted() hook.<br><br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container-fluid&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-12&quot;&gt;<br>         &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>         &lt;p&gt;{{ post.body }}&lt;/p&gt;<br>       &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>Now when you spool up your server, you should get the same routing functionality as with your local data: a main posts page with all posts, and a detail page with individual post data.</p><h4>*Update: A note on APIs, resources, and endpoints</h4><p>As mentioned above there’s a caveat to APIs: I struggled with this for a while before understanding. APIs are built so that there are two basic endpoints: one for <strong>ALL</strong> resources (i.e. all the data the API offers), and another for <strong>EACH</strong> resource individually (i.e. every post, every user, every location, etc).</p><p>So if you go to <a href="https://jsonplaceholder.typicode.com/posts/1">https://jsonplaceholder.typicode.com/posts/</a> you’ll get back an array of <strong>ALL</strong> posts from the API.</p><p>If you go to <a href="https://jsonplaceholder.typicode.com/posts/1">https://jsonplaceholder.typicode.com/posts/1</a> you’ll get back a <strong>single</strong> post entry, with theid of 1. Every post and data type has this format. And this is why dynamic routing will work with a remote data source. If you append an id to the end of the url, a resource exists at that url, so you get your data back.</p><p>If you publish your data as a.json file to github pages for example (so it’s consumable as an API enpoint), or use other simple publishing tools to have your data online and consumable, it’s important to understand that the same logic applies (i.e. it won’t work the same way).</p><p>First, with the github pages idea, your endpoint will have a .json extension i.e. <a href="https://masonmedia.github.io/vue_routing_demo/posts/posts.json">https://yourusername.github.io/vue_routing_demo/posts/posts.json</a>. Even though this will return all your post data, and even if you set up your dynamic routing in your Vue application, the routing will not work. You can’t create dynamic routes from a single endpoint. If you try you’ll get <a href="https://masonmedia.github.io/vue_routing_demo/posts/posts.json">https://yourusername.github.io/vue_routing_demo/posts/posts.json</a>/1 which will return an error because nothing exists at that url.</p><blockquote>I ran through a tutorial that actually used Netlify as a remote API in the same vein as above. But it only worked because the author published each individual resource as a separate .json file. He could then use his route params to dynamically generate routes based on those resources. While it was cool, simple, and easy to set up for a small project, it’s labour intensive and not a viable option for anything remotely bigger than a small website.</blockquote><h4>Creating a go back button</h4><p>The Vue router has a built-in function for manipulating browser history i.e. using the browser back and forward buttons. The router.go() function takes an integer as a parameter — this tells the browser how many pages to go back or forward from where you currently are. It’s perfect for a simple go back button:</p><pre><br>// go back by one record, the same as router.back()<br>router.go(-1)<br><br>// go forward by one record, the same as router.forward()<br>router.go(1)<br><br>// go forward by 3 records<br>router.go(3)<br><br>//practical use<br><br>&lt;template&gt;<br>  &lt;div class=&quot;container-fluid&quot;&gt;<br>    &lt;div class=&quot;row&quot;&gt;<br>      &lt;div class=&quot;col-lg-12&quot;&gt;<br>         &lt;h1&gt;{{ post.title }}&lt;/h1&gt;<br>         &lt;p&gt;{{ post.body }}&lt;/p&gt;<br>         &lt;button @click=&quot;router.go(-1)&quot;&gt;Back&lt;/button&gt;<br>       &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p><em>*More on traversing history in the Vue router docs </em><a href="https://router.vuejs.org/guide/essentials/navigation.html#traverse-history"><em>here</em></a><em>.</em></p><h4>Using other parameters</h4><p>Route params are just variables that match. You can use (almost) anything as a route parameter. It just has to match the keys in your data: i.e. if you declare a :slug parameter, which is super common (i.e. /post/:slug), you have to have a slug key in your JSON for the computed property to find and match. As mentioned above as well, the key can’t have just any type of data. The parameter becomes the url for that post/item so if you use the title for example (wordpress post urls tend to be the title of the post) and it has spaces and special characters (colons, brackets, commas, etc) you’ll have to have a separate slug key that separates the words with dashes or somehow otherwise returns a useable data value.</p><h4>Routing directly from one dynamic route to another</h4><p>You don’t always want to navigate back to a main posts page from a specific article to find more articles. And if you have a smaller e-commerce app with limited products you might want to be able to see all available products and navigate between them at any time, more like a website. In these cases we run into a problem with dynamic routes: vue-router won’t render changes to route parameters. For example, the router won’t know that the current route, blog/post/id1 has changed to blog/post/id4 , even though the url will reflect the change. Here’s where I don’t know all the logic behind it, but I know vue <a href="https://vuejs.org/guide/essentials/watchers.html">watchers</a> work to alleviate this problem by “reacting” to route param changes.</p><p>What did work for me however was a solution from <a href="https://stackoverflow.com/questions/40404787/best-practice-for-reacting-to-params-changes-with-vue-router">this post</a> using the :key=”” attribute on the &lt;router-view /&gt;. Adding $route.fullPathrerenders all dynamic routes with the accurate/updated data:</p><pre>// App.vue<br>// This works with the $route in Vue 3 but you can also import the useRoute()<br>// method to expose a route variable<br><br>&lt;router-view :key=&quot;$route.fullPath&quot;&gt;&lt;/router-view&gt; </pre><p>*But then another problem arose — <strong>my page transitions stopped working</strong>. The next line down in the same <a href="https://stackoverflow.com/questions/40404787/best-practice-for-reacting-to-params-changes-with-vue-router">thread</a> suggested putting the $route.fullPath on the component inside the router-view which worked like a charm:</p><pre>&lt;router-view<br>  v-slot=&quot;{ Component }&quot;&gt;<br>  &lt;transition <br>  name=&quot;slide-fade&quot;<br>  mode=&quot;out-in&quot;&gt;<br>    &lt;component :is=&quot;Component&quot; :key=&quot;$route.fullPath&quot; /&gt;<br>  &lt;/transition&gt;<br>  &lt;/router-view&gt;</pre><h4>Resources</h4><p>Here are a few resources to get more info on the topic:</p><p>Vue School offers two great free courses on Vue Router. The frist is Vue Router for Everyone taught by Debbie O’Brien who is a fantastic and accessible teacher. The second is essentially the same course but using Vue Router 4 with Daniel Kelly — it’s quite a bit slower, but also better in that he explains dynamic routing with API data. Both use Vue 2 so you’ll have to migrate elements to Vue 3 yourself.</p><p>Vue Router for Everyone<a href="https://vueschool.io/lessons/vue-router-named-routes-and-params"><br>https://vueschool.io/lessons/vue-router-named-routes-and-params</a></p><p>Vue Router 4 for Everyone<a href="https://vueschool.io/lessons/dynamic-routes"><br>https://vueschool.io/lessons/dynamic-routes</a><br><a href="https://vueschool.io/lessons/reacting-to-param-changes">https://vueschool.io/lessons/reacting-to-param-changes</a></p><p>BlogRocket has a couple great tutorials on dynamic routing <a href="https://www.digitalocean.com/community/tutorials/how-to-navigate-between-views-with-vue-router"><strong>here</strong></a> and <a href="https://blog.logrocket.com/ultimate-guide-vue-router/"><strong>here</strong></a>.</p><p>Great medium tutorial building a news blog/app with Vue and dynamic routing <a href="https://nirajthing.medium.com/building-a-news-application-with-dynamic-routing-on-vue-js-387d4ecd706e"><strong>here</strong></a>.</p><p>Vue Router docs for dynamic routing <a href="https://router.vuejs.org/guide/essentials/dynamic-matching.html">here</a>.</p><h4>Conclusion</h4><p>So there you have it. Dynamic routing with local JSON data and with dynamic API data. It was a long rabbit hole of a trip trying to wrap my head around all of this, and I’m still sorting out why some APIs work and others don’t. But the basics are here with, I hope, a pared down explanation that makes some sense. Hopefully this helps you understand and get into the dynamic routing world — it’s super exciting and useful for a lot of applications.</p><blockquote>If you like this post, feel free to <a href="https://www.buymeacoffee.com/bassfx">support my work</a>, and don’t forget to subscribe and check out more posts on my <a href="https://medium.com/@andrewmasonmedia">medium home page</a>. Reach out and get more info on my <a href="https://andrewmasonmedia.com/">website</a> (built with Vue 3, the medium <a href="https://rss2json.com/">rss2feed</a>, Bootstrap 5, and GSAP).</blockquote><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30270b82919f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to limit the length of text (strings) in javascript and Vuejs]]></title>
            <link>https://medium.com/@andrewmasonmedia/how-to-limit-the-length-of-text-strings-in-javascript-and-vuejs-17a50af071a7?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/17a50af071a7</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[text]]></category>
            <category><![CDATA[string-methods]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 15:40:19 GMT</pubDate>
            <atom:updated>2023-04-04T15:58:34.870Z</atom:updated>
            <content:encoded><![CDATA[<p>In building a travel website project recently I needed to limit the length of a string as part of an API GET request. I was using the Wikipedia API to return just the text content of a page (as JSON), without all the images, links, etc (which in itself is a maddening rabbit hole of googling). I wanted to show just a short snippet of text so each page would have a little intro but not the entire payload of the Wiki page. This is what I found.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s8ew3q2j4wSTEji2" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Intro</h4><p>One of the first points to mention is how tricky it was to word/phrase this question when I was googling. I wanted to limit or reduce the length (or amount) of text that was coming back from an API response. But in just one key:value in the JSON. Like I wanted 3 paragraphs instead of 3 pages worth of text content. But text in javascript is a <em>string</em>. And if you want to shorten a string, you can’t say .reduce() or .trim(), as these are JS methods that do something else.</p><p>So the best responses I found were from searching:</p><p>How to truncate a string in Javascript<br>Shorten a string without cutting words<br>How to limit the length of string in Javascript</p><h4>Basics</h4><p>The basics of reducing the length of a string aren’t too tricky. There are two javascript methods that do it short and quick:</p><p>.slice() and .substr()</p><ol><li>.slice() literally slices a string (or an array, etc) between two points (i.e. a start and end). The two points are indexes passed as parameters which return a result with the extraneous values removed i.e.</li></ol><pre>// slice method<br>.slice(index 1, index 2)<br><br>let string = &#39;This is a string of text.&#39;;<br><br>let result = string.slice(0, 3);<br><br>console.log(result);<br><br>//result<br>This</pre><blockquote>More on .slice() <a href="https://www.w3schools.com/jsref/jsref_slice_string.asp">here</a>.</blockquote><p>2. .substr()performs a similar action, cutting a string between a range — but with substr() the parameters are characters, not indexes. Similar to .slice() the two points are indexes passed as parameters which return a result with the extraneous values removed i.e.</p><pre>let string = &#39;This is a string of text.&#39;;<br><br>let result = string.substr(0, 4);<br><br>console.log(result);<br><br>//result<br>This</pre><blockquote>More on substring() <a href="https://www.w3schools.com/jsref/jsref_substr.asp">here</a>.</blockquote><h4>Fetching Data from an API and rendering a truncated response string (or <em>Shortening a sentence, without cutting words</em>).</h4><p>Now, back to the goal, I want a shorter text response from my API request, and I want to add an ellipsis at the end so it didn’t look weird.</p><pre>&lt;script setup&gt;<br>import { onMounted, ref } from &#39;vue&#39;<br><br>const stringData = ref([]);<br><br>function getData() {<br>  fetch(&#39;https://yourapidata.com&#39;)<br>    .then((response) =&gt; response.json())<br>    .then((data) =&gt; {<br>     //set data gotten from API call to our empty stringData variable<br>      stringData.value = data;<br>      console.log(stringData.value)<br>    });<br>}<br><br>onMounted(() =&gt; {<br>  getData();<br>})<br><br>// result<br>// Let&#39;s say for argument the stringData result is &#39;This is a string.&#39;<br><br>&lt;/script&gt;<br><br>&lt;template&gt;<br>// We can apply the methods above in a couple ways<br>  <br>  &lt;div v-for=&quot;(string, index) in stringData&quot; :key=&quot;index&quot;&gt;<br>    <br>    &lt;p&gt;{{ string.slice(0, 4) + &#39;...&#39; }}&lt;/p&gt;<br>    // renders &#39;This&#39;<br><br>    &lt;p&gt;{{ string.substr(0, 5) + &#39;...&#39; }}&lt;/p&gt;<br>    // renders &#39;This&#39;<br>  <br>  &lt;/div&gt;<br>&lt;?template&gt;</pre><pre>&lt;script setup&gt;<br>import { onMounted, ref } from &#39;vue&#39;<br><br>const stringData = ref([]);<br><br>function getData() {<br>  fetch(&#39;https://yourapidata.com&#39;)<br>    .then((response) =&gt; response.json())<br>    .then((data) =&gt; {<br>     //set data gotten from API call to our empty stringData variable<br>      stringData.value = data;<br>      console.log(stringData.value)<br>    });<br>}<br><br>onMounted(() =&gt; {<br>  getData();<br>})<br><br>// result<br>// Let&#39;s say for argument the stringData result is &#39;This is a string.&#39;<br><br>&lt;/script&gt;<br><br>&lt;template&gt;<br>// We can apply the methods above in a couple ways<br>  <br>  &lt;div v-for=&quot;(string, index) in stringData&quot; :key=&quot;index&quot;&gt;<br>    <br>    &lt;p&gt;{{ string.slice(0, 4) + &#39;...&#39; }}&lt;/p&gt;<br>    // renders &#39;This&#39;<br><br>    &lt;p&gt;{{ string.substr(0, 5) + &#39;...&#39; }}&lt;/p&gt;<br>    // renders &#39;This&#39;<br>  <br>  &lt;/div&gt;<br>&lt;?template&gt;</pre><p>We can also use a great function (from link below) with parameters that can not only truncate the length of the string, but also make sure it doesn’t cut off any words, plus add an ellipsis at the end:</p><pre>&lt;script setup&gt;<br>import { onMounted, ref } from &#39;vue&#39;<br><br>const stringData = ref([]);<br><br>function getData() {<br>  fetch(&#39;https://yourapidata.com&#39;)<br>    .then((response) =&gt; response.json())<br>    .then((data) =&gt; {<br>     //set data gotten from API call to our empty stringData variable<br>      stringData.value = data;<br>      console.log(stringData.value)<br>    });<br>}<br><br>onMounted(() =&gt; {<br>  getData();<br>})<br><br>// result<br>// &#39;This is a string.&#39;<br><br>// function to shorten the returned string: <br>// text = your returned string<br>// max = number of characters<br>// From this StackOverflow post https://stackoverflow.com/questions/5454235/shorten-string-without-cutting-words-in-javascript<br><br>function shorten(text, max) {<br>    return text &amp;&amp; text.length &gt; max ? text.slice(0, max).split(&#39; &#39;).slice(0, -1).join(&#39; &#39;) : text<br>}<br><br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  <br>  //loop over the response array<br>  &lt;div v-for=&quot;(string, index) in stringData&quot; :key=&quot;index&quot;&gt;<br>    <br>    &lt;p&gt;{{ shorten(string.text, 5) }}&lt;/p&gt;<br>    // renders &#39;This&#39;<br><br>    // With ellipsis<br>    &lt;p&gt;{{ shorten(string.text, 5) + &#39;...&#39; }}&lt;/p&gt;<br>    // renders &#39;This...&#39;<br>  <br>  &lt;/div&gt;<br>&lt;?template&gt;</pre><h4>Conclusion</h4><p>For me this last one did the trick. I need to limit the length of string, but not lose parts of a word in a sentence, and add an ellipsis at the end to show there is more text to be found on the original Wikipedia site. There are more great approaches to this on the original Stack Overflow response <a href="https://stackoverflow.com/questions/5454235/shorten-string-without-cutting-words-in-javascript"><strong>here</strong></a>.</p><blockquote>If you like this post, feel free to <a href="https://www.buymeacoffee.com/bassfx">support my work</a>, and don’t forget to subscribe and check out more posts on my <a href="https://medium.com/@andrewmasonmedia">medium home page</a>. Reach out and get more info on my <a href="https://andrewmasonmedia.com/">website</a> (built with Vue 3, the medium <a href="https://rss2json.com/">rss2feed</a>, Bootstrap 5, and GSAP).</blockquote><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17a50af071a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to fix ENOENT, EACCESS and other errors when running npm install]]></title>
            <link>https://medium.com/@andrewmasonmedia/how-to-fix-enoent-eaccess-and-other-errors-when-running-npm-install-45209113afe9?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/45209113afe9</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[error]]></category>
            <category><![CDATA[vitejs]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Wed, 08 Mar 2023 01:30:50 GMT</pubDate>
            <atom:updated>2023-04-04T16:01:16.531Z</atom:updated>
            <content:encoded><![CDATA[<p>I was following one of my own <a href="https://medium.com/@andrewmasonmedia/set-up-a-vue-app-with-vite-sass-vue-router-and-other-goodies-30647b82c271">tutorials</a> to set up a new Vue project with Vite but I kept getting errors when I ran npm install. I had no clue what was happening. I could install Vite, install Vue, make all my custom selections, and create the project folder. But things went haywire when I tried to install dependencies. Here’s what worked to fix it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ugMPSIsYNw6A61E4" /><figcaption>Photo by <a href="https://unsplash.com/@visuals?utm_source=medium&amp;utm_medium=referral">visuals</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Intro</h4><p>I ran through all the same commands and steps I’d outlined <a href="https://medium.com/@andrewmasonmedia/set-up-a-vue-app-with-vite-sass-vue-router-and-other-goodies-30647b82c271"><strong>here</strong></a>. But every time I came to npm install my terminal went red. I could override using sudo but a) why should I have to do that, and b) when I did, I had to repeat it for every command thereafter, even trying to start a dev server with npm run dev.</p><p>It went like this:</p><p>I installed Vite and set up a new Vue project. That worked as expected until I ran:</p><pre>npm install</pre><p>At which point I got these errors:</p><pre>npm ERR! code ENOENT<br>[...lots of other error logs...]<br>npm ERR! enoent This is related to npm not being able to find a file.</pre><h4>Solutions</h4><p>Then I ran:</p><pre>npm cache verify </pre><p>After which I got:</p><pre><br>npm ERR! code EACCES <br>npm ERR! Your cache folder contains root-owned files, due to a <br>bug in previous versions of npm which has since been addressed. </pre><p>Followed by what appeared to be a solution:</p><pre> <br>npm ERR! To permanently fix this problem, please run:<br>sudo chown -R 501:20 “/Users/yourusername/.npm” </pre><p>So I ran:</p><pre>sudo chown -R 501:20 “/Users/myusername/.npm </pre><p>Which solved the problem. No more npm ERR!, no more sudo, no more red.</p><p>Some other options to try if the above doesn’t work for you:</p><pre># update npm to the latest version<br>npm install -g npm@latest<br><br># clean/clear npm cache<br>npm cache clean --force<br><br># delete node modules and package-lock.json <br>npm rm -rf node_modules &amp;&amp; rm package-lock.json<br><br># rerun npm install for dependencies<br>npm install </pre><p>Check out <a href="https://sebhastian.com/npm-err-enoent/">this article</a> for more.</p><h4>Conclusion</h4><p>There’s nothing worse than errors even before you start coding. Hopefully this helps get you out of the frustrating error zone and back into a creative space. Let me know if this works for you and feel free to comment if it doesn’t, or you come across better options.</p><blockquote>If you like this post, feel free to <a href="https://www.buymeacoffee.com/bassfx">support my work</a>, and don’t forget to subscribe and check out more posts on my <a href="https://medium.com/@andrewmasonmedia">medium home page</a>. Reach out and get more info on my <a href="https://andrewmasonmedia.com/">website</a> (built with Vue 3, the medium <a href="https://rss2json.com/">rss2feed</a>, Bootstrap 5, and GSAP).</blockquote><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45209113afe9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get the first item in an array in Vue.js]]></title>
            <link>https://medium.com/@andrewmasonmedia/how-to-get-the-first-item-in-an-array-in-vue-js-4452e1820aee?source=rss-8e078f245449------2</link>
            <guid isPermaLink="false">https://medium.com/p/4452e1820aee</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[loops-in-javascript]]></category>
            <category><![CDATA[destructuring]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[filters]]></category>
            <dc:creator><![CDATA[masonmedia]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 03:24:51 GMT</pubDate>
            <atom:updated>2023-04-04T16:01:37.812Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s always useful being able to single out the first item in an array. Be it for styling, conditional rendering, or more, there are a few simple ways we can do this with Vue.js using both baked-in Vue methods, and some javascript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*67wrL6hR6F5denCm" /><figcaption>Photo by <a href="https://unsplash.com/@djpaine?utm_source=medium&amp;utm_medium=referral">DJ Paine</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are a number of ways to get the first value in an array using Vue.js. In this article we’ll use:</p><p>1. The slice() method<br>2. The filter() method<br>3. arr[index]<br>4. Array Destructuring<br>5. Using the array index inside a v-for loop</p><p>First let’s create a simple example array to use:</p><p>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]</p><p>Then let’s declare it in Vue using the Options API as a data option:</p><pre>export default {<br>data() {<br>   basses: [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>  }<br>}</pre><p>Or in Vue 3 with the Composition API as a constant:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>&lt;/script&gt;</pre><blockquote>For ease through the rest of the article I’ll use the Composition API variation above.</blockquote><p>1First, the slice() method. slice() lets you return either a single item, or a range of values in an array by specifying the starting and ending indexes you want. It will cut out whatever isn’t in this range, and return only the selected values from the total array.</p><pre>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br><br>basses.slice(0, 1)<br><br>// output<br>// Fender</pre><p>In the template, we can then render the sliced array in a couple ways:</p><p>1. By looping over it with v-for :</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(bass, index) in basses.slice(0, 1)&quot; :key=&quot;index&quot;&gt;<br>        {{ bass }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// Fender</pre><p>2. By using a computed property:</p><pre><br>&lt;script setup&gt;<br>import { computed } from &#39;vue&#39;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;];<br>const bassSlice = computed(() =&gt; basses.slice(0, 1));<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(item, index) in bassSlice&quot; :key=&quot;index&quot;&gt;<br>        {{ item }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// Fender</pre><p>2 Next is the filter() method. As its name implies filter() filters out one or more items from an array based on some condition/preference. We can use this in a couple ways, similar to slice().</p><ol><li>Declare a constant bassFilter that makes use of the optional index property, which loops over the array and accesses the index of every item. We can then filter out each array element by assigning them to different variables, singling out the first for our example.</li></ol><p>So here we specify the index we want (i.e. 0) and assign it to the bassFilter constant:</p><pre><br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>const bassFilter = basses.filter((bass, index) =&gt; index == 0);<br>console.log(bassFilter)<br><br>// returns [&#39;Fender&#39;]</pre><p>We can then use bassFilter to render the first item in the array.</p><p>*A note at this point — like the example above, even though we’re only rendering the first value, we have to iterate over it as though it’s still an array (which it is). filter()returns a new array with the filtered value(s) in it. If you don’t, you’ll return the entire array with a single value inside, not the first value we want as a string, i.e:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;];<br>const bassFilter = basses.filter((bass, index) =&gt; index == 0);<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li&gt;<br>        {{ bassFilter }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// [&#39;Fender&#39;]</pre><p>So you have to use v-for to get the value of the first element to render:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>const bassFilter = basses.filter((bass, index) =&gt; index == 0);<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(bass, index) in bassFilter&quot; :key=&quot;index&quot;&gt;<br>        {{ bass }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// Fender</pre><p>2. You can also use bracket notation without needing to loop over the filtered array:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>const bassFilter = basses.filter((bass, index) =&gt; index == 0);<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li&gt;<br>        {{ bassFilter[0] }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// Fender</pre><p><a href="https://www.freecodecamp.org/news/javascript-array-filter-tutorial-how-to-iterate-through-elements-in-an-array/"><strong><em>Here</em></strong></a><em> is a great article for more on the </em><em>filter() method.</em></p><p>3 The third method is using the arr[index] approach. Here, you specify the index of the array you want by adding square brackets at the end of the array variable. This is an older approach but works nicely if you have a single element (especially the first or last) you want to return from an array.</p><p>In our template, we can render in a similar way, looping over the array:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(bass, index) in basses[0]&quot; :key=&quot;index&quot;&gt;<br>        {{ bass }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// Fender</pre><p><strong>Sidenote:</strong> Like in example #2, we again have to loop over the array to render the first value as a string. If you don’t iterate over it, you’ll be returning the entire array with a single value inside, not just the first value itself, i.e:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li&gt;<br>        {{ basses[0] }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// [&#39;Fender&#39;]<br></pre><p>3 The third method is <strong>array destructuring</strong>. Using destructuring we can extract data from arrays by assigning array values to newly named variables.</p><p>For example:</p><pre>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br><br>let [Jazz, ACseries, Monarch, Talman] = basses<br><br>console.log(Jazz)<br>console.log(ACseries)<br><br>// output<br>// Fender<br>// Fbass<br>// etc, etc.</pre><p>This seems kind of semantic though — all we’re doing is using a different approach to assign new variable names to single array values.</p><p>What’s valuable right away though is being able to single out a given value, especially the first:</p><pre>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br><br>let [Jazz] = basses<br><br>or let [Jazz,,,,] = basses // this omits the remaining array values (one comma for every value, not including the first comma).<br>or let [Jazz,...restOfBasses] // this assign all the remaining array values to the restOfBasses variable.<br><br>console.log(Jazz)<br><br>// output<br>// Fender</pre><p>So again in the template we can do:</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>let [Jazz] = basses<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li&gt;<br>        {{ Jazz }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output <br>// Fender<br></pre><p><em>Find out more about array and object destructuring </em><a href="https://www.freecodecamp.org/news/array-and-object-destructuring-in-javascript/"><strong><em>here</em></strong></a><em>.</em></p><p>4 The fourth approach is using the array index along with some CSS and conditional rendering to return only the first item. It’s a little verbose but shows how you can creatively use the array index which is invaluable in a variety of applications.</p><p>In a lot of Vue articles you’ll see code snippets of v-for loops with no index specified.</p><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;bass in basses&quot;&gt;<br>        {{ bass }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><blockquote>Vite and the Vue CLI will scream “error” when rendering loops if you don’t have a :key=&quot;&quot; specified on your v-for. Every loop requires a key to differentiate each entry in the array for rendering. You can usually get away by using key=”bass.id” , even if there’s no actual <em>id</em>, but a better way is to use the array <strong>index</strong>.</blockquote><pre>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;li v-for=&quot;(bass, index) in basses&quot; :key=&quot;index&quot;&gt;<br>        {{ bass }}<br>      &lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;</pre><p>What this then does is give you access to the index for styling or conditional rendering. For our example of returning the first item in an array, you can use v-if to only show the first element in the array if the condition is met. If the index is 0 (the first entry), show it. If not, don’t.</p><pre>&lt;script setup&gt;<br>const basses = [&#39;Fender&#39;, &#39;Fbass&#39;, &#39;Fodera&#39;, &#39;Ibanez&#39;]<br>&lt;/script&gt;<br><br>&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h1&gt;Basses:<br>    &lt;ul&gt;<br>      &lt;span v-for=&quot;(bass, index) in basses&quot; :key=&quot;index&quot;&gt;<br>        &lt;li v-if=&quot;index === 0&quot;&gt;{{ item }}&lt;/li&gt;<br>      &lt;/span&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>// output<br>// Fender</pre><h4>Conclusion</h4><p>So there we have a few different ways of getting the first item in an array. What’s great about all of them is they really open doors to different ways of manipulating arrays and array values.</p><blockquote>If you like this post, feel free to <a href="https://www.buymeacoffee.com/bassfx">support my work</a>, and don’t forget to subscribe and check out more posts on my <a href="https://medium.com/@andrewmasonmedia">medium home page</a>. Reach out and get more info on my <a href="https://andrewmasonmedia.com/">website</a> (built with Vue 3, the medium <a href="https://rss2json.com/">rss2feed</a>, Bootstrap 5, and GSAP).</blockquote><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4452e1820aee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>