Skip to content

preview command should check if server is defined #12236

@rgaiacs

Description

@rgaiacs

Bug description

This was first reported as a discussion in #12227.

In

// Default project types can't be served
const projType = projectType(project?.config?.project?.[kProjectType]);
if (
projType.type === "default" &&
!isMdFormat("docusaurus-md", project?.config?.format) &&
!isMdFormat("hugo-md", project?.config?.format)
) {
quarto preview is limited to the formats docusaurus-md and hugo-md.

But with the introduction of preview.serve in the project options, the above logic is out of date and should, instead, check if preview.serve is defined.

Steps to reproduce

Create a extension that defines project.preview.serve but uses a format other than docusaurus-md and hugo-md. For example,

title: Hugo
author: RStudio, PBC
organization: quarto
contributes:
  project:
    project:
      type: default
      detect:
        - ["hugo.toml", "content"]
        - ["config.toml", "content"]
        - ["config/_default/config.toml", "content"]
      render:
        - "**/*.qmd"
        - "**/*.ipynb"
      preview:
        serve:
          cmd: "hugo serve --port {port} --bind {host} --navigateToChanged"
          env:
            HUGO_RELATIVEURLS: "true"
          ready: "Web Server is available at"
    format: mwe-md
  formats:
    md:
      variant: gfm+yaml_metadata_block+definition_lists+smart
      prefer-html: true
      fig-format: retina
      fig-width: 8
      fig-height: 5
      wrap: preserve

Actual behavior

quarto preview shows

ERROR: The project '' is a default type project which doesn't support project wide previewing unless there is an 'index' file present.

Please preview an individual file within this project instead.

Stack trace:

Please preview an individual file within this project instead.
    at serveProject (file:///opt/quarto/bin/quarto.js:108009:23)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async Command.actionHandler (file:///opt/quarto/bin/quarto.js:108751:9)
    at async Command.execute (file:///opt/quarto/bin/quarto.js:8253:13)
    at async Command.parseCommand (file:///opt/quarto/bin/quarto.js:8143:20)
    at async quarto (file:///opt/quarto/bin/quarto.js:127391:9)
    at async file:///opt/quarto/bin/quarto.js:127418:9
    at async file:///opt/quarto/bin/quarto.js:127273:20
    at async mainRunner (file:///opt/quarto/bin/quarto.js:127275:9)
    at async file:///opt/quarto/bin/quarto.js:127409:5

Expected behavior

The custom preview server defined in project.preview.serve.cmd to run. For the provided example, quarto preview should show something like

Preparing to preview
...

Watching files for changes
Watching for changes in /home/raniere/git.gesis.org/rse/quarto-gesis/{content,themes}
Watching for config changes in /home/raniere/git.gesis.org/rse/quarto-gesis/hugo.toml, /home/raniere/git.gesis.org/rse/quarto-gesis/themes/hugo-gesis/hugo.toml
Start building sites … 
hugo v0.129.0+extended linux/amd64 BuildDate=2024-08-13T17:51:38Z VendorInfo=ubuntu:0.129.0-2


                   | EN  
-------------------+-----
  Pages            | 16  
  Paginator pages  |  0  
  Non-page files   |  1  
  Static files     |  1  
  Processed images |  0  
  Aliases          |  0  
  Cleaned          |  0  

Built in 65 ms
Browse at http://localhost:4825/
Environment: "development"
Serving pages from disk
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:4825/quarto-gesis/ (bind address 127.0.0.1)

Your environment

  • OS: Ubuntu 25.04 on WLS2

Quarto check output

Quarto 1.7.14
[✓] Checking environment information...
      Quarto cache location: /home/raniere/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.7.14
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Tex:  (not detected)

[✓] Checking Chrome Headless....................OK
      Chrome:  (not detected)

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.13.2
      Path: /usr/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........OK
      Version: 4.4.3
      Path: /usr/lib/R
      LibPaths:
        - /home/raniere/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.49
      rmarkdown: 2.29

[✓] Checking Knitr engine render......OK

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpreviewissues related to the `preview` command

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions