|
| 1 | +#Contributing to QuickSnip |
| 2 | + |
| 3 | +>THIS FILE NEEDS TO BE REWORKED. IT'S IMPORTED FROM PREVIOUS VERSION FOR TESTING. |
| 4 | +
|
| 5 | +Hey there! 👋 First off, thanks for taking the time to contribute! ❤️ |
| 6 | + |
| 7 | +You can contribute in two main ways: |
| 8 | + |
| 9 | +-**Improving the code** (like fixing bugs or adding cool new features) |
| 10 | +-**Adding new code snippets** (or improving the existing ones!) |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +##Improving the code |
| 15 | + |
| 16 | +###How to report bugs |
| 17 | + |
| 18 | +If you spot a bug in the codebase or issues with the documentation, please open up a[GitHub issue](https://github.com/technoph1le/quicksnip/issues) detailing the problem before creating a PR. Once confirmed with maintainers, you can then create a PR. |
| 19 | + |
| 20 | +###How to propose new features |
| 21 | + |
| 22 | +If you are interested in proposing new features, please open up a new[GitHub discussion](https://github.com/technoph1le/quicksnip/discussions) with details for the proposed feature. |
| 23 | + |
| 24 | +Please do not create a PR for a new feature without first discussing it with the maintainers. If you create a PR for a new feature without discussing it first, then your PR will be closed. |
| 25 | + |
| 26 | +--- |
| 27 | + |
| 28 | +##Snippets Guidelines |
| 29 | + |
| 30 | +###Snippet Tags |
| 31 | + |
| 32 | +- Tags must describe the snippet with simple word. |
| 33 | + |
| 34 | +Here's an example: |
| 35 | + |
| 36 | +```md |
| 37 | +--- |
| 38 | +title: Convert Number to Currency |
| 39 | +description: Converts a number to a currency format with a specific locale. |
| 40 | +author: axorax |
| 41 | +tags: number,currency |
| 42 | +--- |
| 43 | +``` |
| 44 | + |
| 45 | +**Do not use generic keywords or the language itself as a tag`utility` or`javascript`!** |
| 46 | + |
| 47 | +###Snippet Format |
| 48 | + |
| 49 | +**All** snippets should follow the following structure: |
| 50 | + |
| 51 | +- A`code` segment, containing a function with the actual snippet functionnality |
| 52 | +- An`example` segement, containing one or more examples of use |
| 53 | + |
| 54 | +Example in #"diff-eca12c0a30e25b4b46522ebf89465a03ba72a03f540796c979137931d8f92055-empty-55-0" data-selected="false" role="gridcell" tabindex="-1" valign="top"> | 55 | + |
| 56 | +```js |
| 57 | +functionexample(x) { |
| 58 | +return x*2; |
| 59 | +} |
| 60 | + |
| 61 | +// Usage: |
| 62 | +example(5);// Returns: 10 |
| 63 | +``` |
| 64 | + |
| 65 | +If your function doesn't return anything just show how to use it. If the result of your function is too complicated to be expressed in a single comment, your snippet is probably too complex to begin with. |
| 66 | + |
| 67 | +###Snippet boundaries |
| 68 | + |
| 69 | +To ensure your snippet isn’t refused, consider these questions: |
| 70 | + |
| 71 | +-**Does the standard library of my language provide an easy way of doing this ?** |
| 72 | +-**Does that snippet not have a real, and practical use case ?** |
| 73 | +-**Could it be split into separate parts to be better understood ?** |
| 74 | + |
| 75 | +If any answer is yes, then your snippet will most likely get rejected. |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +##Adding Snippets |
| 80 | + |
| 81 | +###Adding a New Snippet |
| 82 | + |
| 83 | +1.**Ensure your snippet match[guidelines](#snippets-guidelines)** |
| 84 | + |
| 85 | +2.**Navigate to the relevant folder:** |
| 86 | + |
| 87 | +- Go to the`/snippets` folder in the root directory. |
| 88 | +- Locate the folder for the programming language of your snippet, such as`javascript` or`python`. |
| 89 | + |
| 90 | +3.**Choose the correct category:** |
| 91 | + |
| 92 | +- Within the language folder, find the relevant category folder for your snippet. |
| 93 | +- If no suitable category exists, refer to[Adding a New Category](#adding-a-new-category). |
| 94 | + |
| 95 | +4.**Create a markdown file:** |
| 96 | + |
| 97 | +- Create a new file with a`.md` extension. |
| 98 | +- Name the file appropriately, keeping it descriptive and concise. |
| 99 | + |
| 100 | +5.**Add your snippet:** |
| 101 | + |
| 102 | +- Use the following format to structure your snippet: |
| 103 | + |
| 104 | +````md |
| 105 | +--- |
| 106 | +title: Name of the snippet |
| 107 | +description: A short explanation of what the snippet does |
| 108 | +tags: tag1, tag2, tag3 |
| 109 | +author: your-github-username |
| 110 | +--- |
| 111 | + |
| 112 | +```lang |
| 113 | +// Your code here |
| 114 | +``` |
| 115 | +```` |
| 116 | + |
| 117 | +Here’s an example for #"diff-eca12c0a30e25b4b46522ebf89465a03ba72a03f540796c979137931d8f92055-empty-118-0" data-selected="false" role="gridcell" tabindex="-1" valign="top"> | 118 | + |
| 119 | +````md |
| 120 | +--- |
| 121 | +title: Format Date |
| 122 | +description: Formats a date in 'YYYY-MM-DD' format. |
| 123 | +author: technoph1le |
| 124 | +tags: date,format |
| 125 | +--- |
| 126 | + |
| 127 | +```js |
| 128 | +const formatDate = (date) => date.toISOString().split("T")[0]; |
| 129 | + |
| 130 | +// Usage: |
| 131 | +console.log(formatDate(new Date())); // Output: '2024-12-10' |
| 132 | +``` |
| 133 | +```` |
| 134 | + |
| 135 | +6.**Use syntax highlighting:** |
| 136 | + |
| 137 | +- Enclose your code with triple backticks (```). |
| 138 | +- Specify the language after the first set of backticks for syntax highlighting. |
| 139 | + |
| 140 | +7.**Test your snippet:** |
| 141 | + |
| 142 | +- Ensure your code runs as expected.\ |
| 143 | + To test that your snippets are formatted correctly use the`snippets:check` script: |
| 144 | + |
| 145 | +``` |
| 146 | + $ npm run snippets:check |
| 147 | + ``` |
| 148 | +
|
| 149 | + It will return nothing if they are well formatted, otherwise it will tell you what the error is. |
| 150 | +
|
| 151 | + *** |
| 152 | +
|
| 153 | + To preview the snippets, start the vite server using: |
| 154 | +
|
| 155 | + ``` |
| 156 | + $ npm run dev |
| 157 | + ``` |
| 158 | +
|
| 159 | + It will use HMR to update the snippets in the `/public` folder, making them available to the frontend. |
| 160 | +
|
| 161 | +Expected file structure: |
| 162 | +
|
| 163 | +```md |
| 164 | +/snippets |
| 165 | +|- language |
| 166 | +|- category-name |
| 167 | +|- your-snippet-here.md |
| 168 | +``` |
| 169 | + |
| 170 | +>Please do**NOT** add or edit anything in`/public` folder. It will be used for consolidating snippets. |
| 171 | +
|
| 172 | +###Editing a Existing Snippet |
| 173 | + |
| 174 | +If you’d like to refine or improve an existing snippet: |
| 175 | + |
| 176 | +1.**Add a`contributors` field:** |
| 177 | + |
| 178 | +- Include your GitHub username under the`contributors` field in the metadata section. |
| 179 | + |
| 180 | +````md |
| 181 | +--- |
| 182 | +title: Name of the snippet |
| 183 | +description: A short explanation of what the snippet does |
| 184 | +tags: tag1, tag2, tag3 |
| 185 | +author: original-author |
| 186 | +contributors: your-github-username |
| 187 | +--- |
| 188 | + |
| 189 | +``` |
| 190 | +Updated code here |
| 191 | +``` |
| 192 | +```` |
| 193 | + |
| 194 | +2.**Credit all contributors:** |
| 195 | + |
| 196 | +- If contributors already exist, add your username separated by a comma |
| 197 | + |
| 198 | +```md |
| 199 | +contributors: contributor1, contributor2, your-github-username |
| 200 | +``` |
| 201 | + |
| 202 | +3.**Document changes:** |
| 203 | + |
| 204 | +- Clearly indicate what you updated and why in your pull request description. |
| 205 | + |
| 206 | +>We want to make sure that original author and contributor(s) are credited for their work. |
| 207 | +
|
| 208 | +###Adding a New Category |
| 209 | + |
| 210 | +If your snippet doesn’t fit into any existing category, you can create a new one! Just make sure it’s unique and doesn’t overlap with others (e.g., don’t create separate categories for “Date” and “Time” when “Date and Time” works). |
| 211 | + |
| 212 | +1.**Create a new category folder:** |
| 213 | + |
| 214 | +- In the relevant language directory, add a new folder. |
| 215 | +- Use a lowercase name with hyphens for separation (e.g.,`file-handling`). |
| 216 | + |
| 217 | +2.**Add snippets:** |
| 218 | + |
| 219 | +- Follow the[Adding a New Snippet](#adding-a-new-snippet) instructions. |
| 220 | + |
| 221 | +Example structure: |
| 222 | + |
| 223 | +```md |
| 224 | +/snippets |
| 225 | +|- python |
| 226 | +|- file-handling |
| 227 | +|- list-manipulation |
| 228 | +|- .... |
| 229 | +``` |
| 230 | + |
| 231 | +###Adding a New Language |
| 232 | + |
| 233 | +If you want to introduce a new programming language, here's how to do it: |
| 234 | + |
| 235 | +1.**Create a language folder:** |
| 236 | + |
| 237 | +- Add a new folder under the`snippets` directory. |
| 238 | +- Name it after the language in lowercase (e.g.,`go`,`ruby`). |
| 239 | + |
| 240 | +2.**Add categories and snippets:** |
| 241 | + |
| 242 | +- Follow the[Adding a New Snippet](#adding-a-new-snippet) and[Adding a New Category](#adding-a-new-category) guidelines. |
| 243 | + |
| 244 | +3.**Include an icon:** |
| 245 | + |
| 246 | +- Add an`icon.svg` file (50x50px) in the same language folder. |
| 247 | +- Use tools like[Resize SVG](https://www.iloveimg.com/resize-image/resize-svg) to ensure the correct size. |
| 248 | + |
| 249 | +4.**Double-check your work:** |
| 250 | + |
| 251 | +- Verify that everything is structured correctly and displays as intended. |
| 252 | + |
| 253 | +--- |
| 254 | + |
| 255 | +##Testing Snippets |
| 256 | + |
| 257 | +To test that your snippets are formatted correctly use the following script: |
| 258 | + |
| 259 | +``` |
| 260 | +$ npm run snippets:check |
| 261 | +``` |
| 262 | + |
| 263 | +It will return nothing if they are well formatted, otherwise it will tell you what the error is. |
| 264 | + |
| 265 | +--- |
| 266 | + |
| 267 | +To preview the snippets, you need to consolidate them, use the following script: |
| 268 | + |
| 269 | +``` |
| 270 | +$ npm run snippets:consolidate |
| 271 | +``` |
| 272 | + |
| 273 | +It will update the snippets in the`/public` folder, making them available to the frontend. |
| 274 | + |
| 275 | +##Final Notes |
| 276 | + |
| 277 | +Whether you’re fixing a tiny typo, writing a new snippet, or dreaming up big features, every bit counts! 🛠️ |
| 278 | + |
| 279 | +If you have any questions or need help, feel free to open a new[GitHub discussion](https://github.com/technoph1le/quicksnip/discussions). |
| 280 | + |
| 281 | +Happy coding! 💻✨ |