As a developer who is always eager to learn and showcase my work, I wanted a "portfolio" application to share my learnings and projects. While searching for inspiration, I stumbled upon Spotlight by TailwindUI and [briandev's spotlight],2 a stunning UI created by the Tailwind CSS team. However, since it is a paid product built with Next.js, I decided to challenge myself by replicating it using SvelteKit, specifically to explore the new features of Svelte 5, which was a release candidate at the time.
My goal was to recreate the spotlight design while integrating additional functionalities such as syntax highlighting with Highlight.js, a dev.to-like new post creation page, a commenting system, and the ability to modify and run some code blocks directly within the application.
Source Code
You can access the complete source code for this project on GitHub:
First, we need to set up TailwindCSS in our SvelteKit project. Follow the official TailwindCSS installation guide for SvelteKit to get started. Once TailwindCSS is installed, we can proceed to configure our layout.
Modifying app.html and Creating +layout.svelte
In app.html, ensure you include some of the theme-switching scripts which allow us to persist the user's desired theme in the browser's localStorage. See src/app.html.
Next, we create +layout.svelte to define our main layout structure:
$props() also have a reserved property, called children, which contains default content. There's a new feature called Snippet.
The $effect rune is used in place of onMount and onDestroy. Learn more about these new runes and other stuff on the Svelte 5 documentation. Also, note how {@render children()} replaces <slot/>. You don't need Svelte stores in Svelte 5. You can have a .svelte.ts file that exposes some variables which use the svelte rune. For instance, in the dev.to-like editor I built, I store tags using this class:
/**
* Represents the state of tags.
*
* @class TagState
* @property {Set<string>} tagList - Set of tags.
* @method addTag - Add a tag to the set.
* @file frontend/src/lib/states/tags.svelte.ts
*/classTagState{// Set of tags.tagList=$state<Set<string>>(newSet());// Add a tag to the set.addTag(tag:string){this.tagList.add(tag);}}exportconsttagState=newTagState();exportconsttagsAbortController=newAbortController();
It serves as my store!!! Beautiful, huh?
Step 2: Integrating Highlight.js
For syntax highlighting, I used Highlight.js. I created a custom wrapper to handle code block rendering and highlighting. Take a look at src/lib/utils/helpers/code.block.ts.
This wrapper supports theme switching between horizon-dark and night-owl, displays filenames, allows code copying, and even runs some code using an iframe for security reasons. The design of the code block component is inspired by TailwindCSS's documentation style.
Step 3: Creating a dev.to-like Custom Editor
Tag Selection with Suggestions
For the tag selection feature, I used a combination of Svelte's reactivity and some functions to provide suggestions as users type. The code works but it can be cleaned further.
Markdown Rich-Text Editor
For the markdown editor, I built a user-friendly markdown editor interface. It has most of dev.to's features including keyboard combinations. It detects the Operating system a user is running and gives key combinations based on this. You can combine three keys. For instance, CMD/CTRL + SHIFT + K will add a code block to the textarea. The parts of the code block are explained as follows:
language is the programming language. filename is the name of the file you want to display its code. {line nos} represents the line numbers, separated by commas, you want to emphasize. runnable denotes whether or not the code can be run. If it's present, it means it can be run. Otherwise, it can't. This custom code block is parsed by a custom parser to extract these parts using regex.
Custom Parser for GitHub Repos
I wrote a custom parser to detect and embed GitHub repositories as well. Just like dev.to's.
The full implementation includes other features and refinements, which you can explore in the source code.
Future Enhancements
The final version of this application for my portfolio will include a backend built with either Go or Rust, incorporating more robust features such as a real-time commenting system. Stay tuned for updates, and feel free to suggest new features or your preferred backend language.
Outro
Enjoyed this article? I'm a Software Engineer and Technical Writer actively seeking new opportunities, particularly in areas related to web security, finance, healthcare, and education. If you think my expertise aligns with your team's needs, let's chat! You can find me on LinkedIn and Twitter.
If you found this article valuable, consider sharing it with your network to help spread the knowledge!