Skip to content

Commit fbe98d3

Browse files
committed
another pass
1 parent b02ae42 commit fbe98d3

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

_blogposts/community/2025-01-01-what-can-i-do-with-rescript.mdx

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Console.log("Hello")
2222
```
2323

2424
Just run `node index.res.js` and you'll see "Hello" logged to the console. You can import compiled ReScript into any project that could import JavaScript.
25+
If you can use `.js` or `.mjs` files, you can use ReScript. This does mean that languages with different file formats like Vue or Svelte require you to import the compiled JavaScript instead of writing it directly in the `.vue` or `.svelte` files.
2526
But real world projects aren't just JavaScript; they use libraries and frameworks. This is where [bindings](https://rescript-lang.org/docs/manual/latest/external) come into play.
2627
A binding is a way to tell ReScript the types and imports from external JavaScript. You can think of bindings in the same way that you need to create a `*.d.ts` file to add types to a JavaScript library that doesn't use TypeScript.
2728

@@ -131,4 +132,11 @@ var formattedDate = DateFns.format("2021-09-01", "MMMM dd, yyyy", {
131132
```
132133
</CodeTab>
133134

134-
You can write new bindings and extend existing types as you need.
135+
You can write new bindings and extend existing types as you need.
136+
137+
## How can I get started?
138+
You can [follow this guide](https://rescript-lang.org/docs/manual/v11.0.0/converting-from-js) to add ReScript to an existing JavaScript project to get a feel for how the language works and interacts with JavaScript.
139+
The forum is also a great place to ask questions! Feel free to drop by and ask how to get started with a specific framework or project that you want to work on,
140+
and you'll probably get great advice and information from users who have already used ReScript for something similar.
141+
142+
Happy coding!

src/BlogArticle.res

+27-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module BlogHeader = {
6363
~category: option<string>=?,
6464
~description: option<string>,
6565
~articleImg: option<string>,
66+
~originalSrc: option<(string, string)>,
6667
) => {
6768
let date = DateStr.toDate(date)
6869

@@ -91,6 +92,17 @@ module BlogHeader = {
9192
</div>
9293
}
9394
)}
95+
{switch originalSrc {
96+
| None => React.null
97+
| Some("", _) => React.null
98+
| Some(_, "") => React.null
99+
| Some(url, title) =>
100+
<div className="mt-1 mb-8">
101+
<a className="body-sm no-underline text-fire hover:underline" href=url>
102+
{React.string(`Originally posted on ${title}`)}
103+
</a>
104+
</div>
105+
}}
94106
<div className="flex flex-col md:flex-row mb-12">
95107
{Array.map(authors, author =>
96108
<div
@@ -150,7 +162,17 @@ let default = (props: props) => {
150162
: React.null
151163

152164
let content = switch fm {
153-
| Ok({date, author, co_authors, title, description, articleImg, previewImg}) =>
165+
| Ok({
166+
date,
167+
author,
168+
co_authors,
169+
title,
170+
description,
171+
articleImg,
172+
previewImg,
173+
originalSrc,
174+
originalSrcUrl,
175+
}) =>
154176
<div className="w-full">
155177
<Meta
156178
siteName="ReScript Blog"
@@ -166,6 +188,10 @@ let default = (props: props) => {
166188
title
167189
description={description->Null.toOption}
168190
articleImg={articleImg->Null.toOption}
191+
originalSrc={switch (originalSrcUrl->Null.toOption, originalSrc->Null.toOption) {
192+
| (Some(url), Some(title)) => Some(url, title)
193+
| _ => None
194+
}}
169195
/>
170196
</div>
171197
<div className="flex justify-center">

src/common/BlogFrontmatter.res

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ type t = {
9999
title: string,
100100
badge: Null.t<Badge.t>,
101101
description: Null.t<string>,
102-
originalLink: Null.t<string>,
102+
originalSrc: Null.t<string>,
103+
originalSrcUrl: Null.t<string>,
103104
}
104105

105106
let decodeBadge = (str: string): Badge.t =>
@@ -142,7 +143,8 @@ let decode = (json: JSON.t): result<t, string> => {
142143
articleImg: json->optional(field("articleImg", string, ...), _)->Null.fromOption,
143144
title: json->(field("title", string, _)),
144145
description: json->(nullable(field("description", string, ...), _)),
145-
originalLink: json->optional(field("originalLink", string, ...), _)->Null.fromOption,
146+
originalSrc: json->optional(field("originalSrc", string, ...), _)->Null.fromOption,
147+
originalSrcUrl: json->optional(field("originalSrcUrl", string, ...), _)->Null.fromOption,
146148
} {
147149
| fm => Ok(fm)
148150
| exception DecodeError(str) => Error(str)

0 commit comments

Comments
 (0)