From 46b46c82e5bc6f0fded56aeccbebb401db78f686 Mon Sep 17 00:00:00 2001 From: terra tauri Date: Sun, 24 May 2026 03:42:10 -0600 Subject: [PATCH] feat: detect .mdx and send Content-Type: text/mdx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `pin share file.mdx` now sends `text/mdx; charset=utf-8` instead of the hardcoded `text/html`. The server (pin#3) does content negotiation on that — for MDX uploads it stores both the rendered HTML and the raw source, and the upload response gets an `mdx_url` field pointing at `GET /p/{id}.mdx`. If the response carries `mdx_url`, print it to stderr alongside the primary URL on stdout, so scripts that capture stdout keep working but agents can grep stderr for the MDX form. Co-Authored-By: Claude Opus 4.7 (1M context) --- main.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 179ac02..dcc631f 100644 --- a/main.go +++ b/main.go @@ -402,8 +402,17 @@ func runShare(args []string) int { return 1 } + // Content-Type from the file extension. MDX uploads let the server + // store the raw .mdx alongside the rendered HTML, which downstream + // agents can fetch via GET /p/{id}.mdx instead of paying tokens for + // the rendered markup. + contentType := "text/html; charset=utf-8" + if strings.HasSuffix(strings.ToLower(args[0]), ".mdx") { + contentType = "text/mdx; charset=utf-8" + } + req, _ := http.NewRequestWithContext(ctx, http.MethodPut, c.Issuer+"/api/pins", bytes.NewReader(body)) - req.Header.Set("Content-Type", "text/html; charset=utf-8") + req.Header.Set("Content-Type", contentType) req.Header.Set("Authorization", "Bearer "+c.AccessToken) req.Header.Set("X-Agent", agent()) @@ -419,12 +428,16 @@ func runShare(args []string) int { return 1 } var out struct { - URL string `json:"url"` + URL string `json:"url"` + MDXURL string `json:"mdx_url"` } if err := json.Unmarshal(rbody, &out); err != nil { fmt.Fprintf(os.Stderr, "pin share: parse: %v\nbody: %s\n", err, rbody) return 1 } + if out.MDXURL != "" { + fmt.Fprintf(os.Stderr, "mdx: %s\n", out.MDXURL) + } fmt.Println(out.URL) return 0 }