src/layouts/Base.astro +18 −11
@@ -94,18 +94,25 @@ const schemas = jsonld ? [jsonld].flat() : [];
</footer>
+ <script>
+ // Fuse.js is bundled as its own file and fetched only when the search dialog is first opened.
+ window.cfiFuse = () => import("fuse.js").then((m) => m.default);
+ </script>
<script is:inline>
- // Search dialog. The index is loaded on first use. Every word typed must appear in a row's
- // name or its second line; countries and pages come first, then entries with an article,
- // then the rest of the history, newest first.
+ // Search dialog. The index and Fuse.js (fuzzy matching, so a typo or a missing accent still
+ // finds its row) are loaded on first use. Every word typed must match a row's name or its
+ // second line; the closest matches come first, and among equals countries and pages lead,
+ // then entries with an article, then the rest of the history, newest first.
(function () {
var dialog = document.getElementById("siteSearch"), input = document.getElementById("searchInput");
var list = document.getElementById("searchResults"), hint = document.getElementById("searchHint");
- var rows = null, loading = null, shown = [], active = 0;
+ var rows = null, fuse = null, loading = null, shown = [], active = 0;
var KIND = { c: "Country", p: "Page", a: "Article", h: "History" }, ORDER = { c: 0, p: 1, a: 2, h: 3 };
function fold(s) { return s.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""); }
function esc(s) { return String(s).replace(/[&<>"]/g, function (ch) { return { "&": "&", "<": "<", ">": ">", '"': """ }[ch]; }); }
function load() {
- if (!loading) loading = fetch(dialog.dataset.index).then(function (r) { return r.json(); }).then(function (data) {
- rows = data.map(function (r, i) { r.i = i; r.k = fold(r.n); r.h = r.k + " " + fold(r.s); return r; });
+ if (!loading) loading = Promise.all([fetch(dialog.dataset.index).then(function (r) { return r.json(); }), window.cfiFuse()]).then(function (got) {
+ rows = got[0].map(function (r, i) { r.i = i; r.k = fold(r.n); r.h = r.k + " " + fold(r.s); return r; });
+ // `k` is the name, `h` the name and second line together, so words may be spread over both
+ fuse = new got[1](rows, { keys: [{ name: "k", weight: 2 }, { name: "h", weight: 1 }], useExtendedSearch: true, ignoreLocation: true, threshold: 0.3, minMatchCharLength: 2, includeScore: true });
render();
}).catch(function () { hint.textContent = "The search index could not be loaded."; });
@@ -114,10 +121,10 @@ const schemas = jsonld ? [jsonld].flat() : [];
function render() {
var words = fold(input.value).split(/\s+/).filter(Boolean);
- if (!rows || !words.length) { shown = []; list.innerHTML = ""; hint.hidden = false; return; }
- var found = rows.filter(function (r) { return words.every(function (w) { return r.h.indexOf(w) >= 0; }); });
+ if (!fuse || !words.length) { shown = []; list.innerHTML = ""; hint.hidden = false; return; }
+ // In Fuse's extended search, words separated by spaces must all match (each one fuzzily).
var q = words.join(" ");
- function rank(r) { return ORDER[r.t] * 10 + (r.k === q ? 0 : r.k.indexOf(q) === 0 ? 1 : r.k.indexOf(q) > 0 ? 2 : 3); }
- found.sort(function (a, b) { return rank(a) - rank(b) || a.i - b.i; });
- shown = found.slice(0, 40); active = 0; hint.hidden = shown.length > 0;
+ function rank(x) { var r = x.item; return x.score + ORDER[r.t] * 0.05 + (r.k === q ? -1 : r.k.indexOf(q) === 0 ? -0.5 : 0); }
+ var found = fuse.search(q).sort(function (a, b) { return rank(a) - rank(b) || a.item.i - b.item.i; });
+ shown = found.slice(0, 40).map(function (x) { return x.item; }); active = 0; hint.hidden = shown.length > 0;
if (!shown.length) hint.textContent = "Nothing found for “" + input.value + "”.";
list.innerHTML = shown.map(function (r, i) {
src/lib/facts.js +17 −0
@@ -63,4 +63,5 @@ const fromHistory = [
{ kicker: "1874 · Egypt", history: "egypt-import-tax-1874", text: "[[EG|Egypt]] forbade importing cannabis in [[h:egypt-first-ban-1868|1868]]. Six years later it put a tax on those same imports." },
{ kicker: "1830 · Brazil", history: "brazil-rio-pango-ban-1830", text: "Rio de Janeiro's council banned cannabis in 1830. A seller paid a fine of 20 milreis; a slave or anyone else caught using it faced up to three days in prison. [[BR|Brazil]]'s other councils followed." },
+ { kicker: "1881 · DR Congo", history: "dr-congo-bena-riamba-1881", text: "Nineteenth-century visitors recorded a cannabis-centred movement among the Bashilenge in today's [[CD|DR Congo]]. Its members called themselves Bena Riamba — ‘sons of hemp’ — and used a communal pipe for holidays, trade agreements and peace settlements." },
{ kicker: "1894 · India", history: "india-hemp-drugs-commission-1894", text: "After hearing nearly 1,200 witnesses, the Indian Hemp Drugs Commission concluded in 1894 that moderate use does practically no harm and that a ban would be unjustified. [[IN|India]] taxed and licensed cannabis until 1985." },
{ kicker: "1915 · Trinidad", history: "trinidad-ganja-licensing-1915", text: "[[TT|Trinidad and Tobago]] set up licensed ganja sellers in 1915. Ten years later it [[h:trinidad-ganja-ordinance-1925|banned the plant outright]]." },
@@ -70,15 +71,26 @@ const fromHistory = [
{ kicker: "1937 · Uruguay", history: "uruguay-narcotics-law-1937", text: "[[UY|Uruguay]] made hashish a state monopoly sold only by pharmacies in 1937. Eighty years later its pharmacies [[h:uruguay-pharmacy-sales-2017|started selling cannabis again]] — this time without a prescription." },
{ kicker: "1940 · Mexico", history: "mexico-brief-legalisation-1940", text: "For five months in 1940 [[MX|Mexico]] let doctors prescribe drugs to users through state dispensaries. The United States cut off its exports of medical narcotics, and Mexico [[h:mexico-regulation-suspended-1940|suspended the rule]]." },
+ { kicker: "1942 · United States", history: "us-hemp-for-victory-1942", text: "Five years after the [[h:us-marihuana-tax-act-1937|Marihuana Tax Act]], the government of the [[US|United States]] made a film called Hemp for Victory and asked farmers to grow it for the war. They planted about 400,000 acres." },
{ kicker: "1944 · United States", history: "us-la-guardia-report-1944", text: "A five-year study ordered by the mayor of New York found in 1944 that marijuana did not lead to addiction, crime or harder drugs. The federal narcotics bureau attacked it, and [[US|US]] law did not change." },
+ { kicker: "1948 · Kiribati and Tuvalu", history: "gilbert-islands-dangerous-drugs-1948", text: "One British colonial ordinance banned ‘Indian hemp’, its resin and even its seeds across the Gilbert and Ellice Islands. Separate versions still govern [[KI|Kiribati]] and [[h:ellice-islands-dangerous-drugs-1948|Tuvalu]]." },
+ { kicker: "1948 · Japan", history: "japan-cannabis-control-act-1948", text: "[[JP|Japan]]'s 1948 ban on cannabis did not punish using it, which shielded hemp farmers who might breathe in their crop. The country had about 25,000 hemp farms in 1950 and 37 in 2016." },
{ kicker: "1953 · Netherlands", history: "netherlands-possession-ban-1953", text: "The [[NL|Netherlands]] only made possessing cannabis an offence in 1953 — just over twenty years before it [[h:netherlands-toleration-1976|became known for tolerating it]]." },
+ { kicker: "1954 · United States", history: "us-toklas-cookbook-1954", text: "Alice B. Toklas's 1954 cookbook contained a recipe for hashish fudge, \"easy to whip up on a rainy day\". It was cut from the first American edition." },
+ { kicker: "1961 · Sri Lanka", history: "sri-lanka-ayurveda-act-1961", text: "In [[LK|Sri Lanka]] the only people who may legally sell cannabis are Ayurvedic practitioners, and their only legal supplier is a state corporation that gets most of it from police seizures." },
{ kicker: "1964 · Israel", history: "israel-mechoulam-thc-1964", text: "The chemist who first isolated THC got his material from the police: 11 pounds of seized Lebanese hashish, which he carried to his laboratory in [[IL|Israel]] on a public bus." },
{ kicker: "1966 · Nigeria", history: "nigeria-indian-hemp-decree-1966", text: "[[NG|Nigeria]]'s 1966 Indian Hemp Decree set death or 21 years for growing cannabis and at least ten years for possessing it. The death penalty [[h:nigeria-death-penalty-removed-1975|was dropped in 1975]]." },
+ { kicker: "1970 · France", history: "france-use-criminalised-1970", text: "Until the last day of 1970, [[FR|France]] punished drug use only when it happened in company. Using alone has been a crime ever since." },
+ { kicker: "1971 · Finland", history: "finland-use-criminalised-1972", text: "[[FI|Finland]] made using drugs a crime in itself after a vote of 92 to 80. In 2026 its parliament [[h:finland-legalisation-initiative-rejected-2026|rejected legalisation]] by 145 to 18." },
{ kicker: "1973 · Nepal", history: "nepal-shops-closed-1973", text: "Kathmandu had licensed cannabis shops until 16 July 1973, when [[NP|Nepal]] cancelled every licence under pressure from the United States and the United Nations." },
{ kicker: "1975 · Comoros", history: "comoros-legalisation-1975", text: "Cannabis was legal in the [[KM|Comoros]] for three years: President Ali Soilih lifted the ban in 1975, and the government that overthrew him [[h:comoros-ban-restored-1978|restored it in 1978]]." },
{ kicker: "1985 · Poland", history: "poland-drug-prevention-act-1985", text: "From 1985 to 1997 possessing drugs was not an offence in [[PL|Poland]] in any quantity: police could confiscate them and nothing more. Since [[h:poland-criminalisation-2000|December 2000]] any amount has been a crime." },
+ { kicker: "1975 · United States", history: "us-ravin-v-state-1975", text: "Since 1975 Alaska's constitution has protected having cannabis at home: the state's Supreme Court found it in the right to privacy." },
+ { kicker: "1976 · South Korea", history: "south-korea-cannabis-control-act-1976", text: "Koreans grew hemp for cloth for centuries and smoking it was no offence until 1976. Today [[KR|South Korea]] [[h:south-korea-abroad-warning-2018|warns its citizens]] that using cannabis abroad, even where it is legal, can be punished when they come home." },
{ kicker: "1976 · United States", history: "us-randall-ruling-1976", text: "After a glaucoma patient won in court in 1976, the federal government of the [[US|United States]] began supplying patients with cannabis it grew itself. In 2011 four people were still receiving it." },
{ kicker: "1980 · Japan", history: "japan-mccartney-arrest-1980", text: "[[JP|Japan]] held Paul McCartney for ten days in 1980 over 219 grams found in his luggage at Tokyo airport, then deported him without charge." },
{ kicker: "1988 · United States", history: "us-dea-judge-young-1988", text: "In 1988 the drug agency's own judge in the [[US|United States]] ruled that cannabis should be rescheduled, calling it one of the safest therapeutically active substances known. The agency's head rejected the ruling." },
+ { kicker: "1989 · Bangladesh", history: "bangladesh-ban-1989", text: "[[BD|Bangladesh]] had government-approved ganja shops until 1989, a leftover of colonial excise law." },
{ kicker: "1989 · Bhutan", history: "bhutan-first-arrest-1989", text: "In [[BT|Bhutan]] cannabis grows prolifically and was long seen mainly as fodder for fattening pigs. The country's first drug arrest came only in 1989." },
+ { kicker: "1993 · Sweden", history: "sweden-prison-for-use-1993", text: "[[SE|Sweden]] added a prison term for drug use in 1993 for a practical reason: an offence that carries prison lets police take a suspect in for a urine or blood test." },
{ kicker: "1995 · Nepal", history: "nepal-pashupati-distribution-ended-1995", text: "Until 1995 the trust that runs [[NP|Nepal]]'s Pashupatinath temple handed holy men marijuana at the Shivaratri festival — taken from the Home Ministry's confiscated stock." },
{ kicker: "2003 · Portugal", history: "portugal-seeds-law-2003", text: "[[PT|Portugal]]'s drug law controls one very specific thing: since 2003 its list has included \"cannabis seeds not intended for sowing\"." },
@@ -91,5 +103,10 @@ const fromHistory = [
{ kicker: "2017 · Indonesia", history: "indonesia-fidelis-case-2017", text: "In [[ID|Indonesia]] a man was jailed for eight months in 2017 for growing cannabis to treat his wife. She died while he was detained." },
{ kicker: "2018 · Poland", history: "poland-first-pharmacy-cannabis-2018", text: "[[PL|Poland]]'s parliament [[h:poland-medical-2017|legalised medical cannabis]] by 440 votes to 2. The first delivery, a year later, was seven kilograms for the whole country and sold out within days." },
+ { kicker: "2018 · Georgia", history: "georgia-constitutional-court-2018", text: "In [[GE|Georgia]] using cannabis in private has been legal since a court ruling in 2018. Growing it and selling it are still crimes, so there is no lawful way to get any." },
+ { kicker: "2021 · Rwanda", history: "rwanda-medical-2021", text: "[[RW|Rwanda]] licenses companies to grow cannabis for export. For anyone else, producing or selling it carries [[h:rwanda-penal-law-2018|twenty years to life]]." },
+ { kicker: "2022 · Italy", history: "italy-referendum-blocked-2022", text: "More than 600,000 people in [[IT|Italy]] signed for a referendum on decriminalising home growing. The Constitutional Court ruled the question inadmissible, and no vote was held." },
{ kicker: "2022 · Russia", history: "russia-griner-sentence-2022", text: "[[RU|Russia]] sentenced an American basketball player to nine years in 2022 for 0.7 grams of cannabis oil. She was freed in a prisoner exchange that December." },
+ { kicker: "2024 · Denmark", history: "denmark-pusher-street-closed-2024", text: "For half a century hashish was sold openly from stalls in Christiania, the freetown in the capital of [[DK|Denmark]]. In 2024, after a series of gang shootings, the residents dug up the street themselves." },
+ { kicker: "2025 · Lebanon", history: "lebanon-cannabis-authority-2025", text: "[[LB|Lebanon]] became the first Arab country to [[h:lebanon-medical-cultivation-2020|legalise growing cannabis]] in 2020. It took five more years to appoint the regulator that issues the licences." },
{ kicker: "2022–2025 · Thailand", history: "thailand-prescription-only-2025", text: "[[TH|Thailand]] went from [[h:thailand-decriminalisation-2022|thousands of open dispensaries]] to prescription-only in three years. Since June 2025 cannabis flower officially requires a prescription." },
{ kicker: "2024 · Morocco", history: "morocco-royal-pardon-2024", text: "[[MA|Morocco]]'s sultan [[h:morocco-hassan-regulations-1890|licensed tribes of the Rif to grow kif]] in 1890. In 2024 its king pardoned 4,831 people convicted, prosecuted or wanted over growing it." },